//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hustcad.plm.pdm.flowbusiness.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.hustcad.plm.basic.entity.BaseFlowObjectTask;
import com.hustcad.plm.basic.entity.BaseObject;
import com.hustcad.plm.basic.log.LogEventEnum;
import com.hustcad.plm.basic.util.TyCommonExtUtil;
import com.hustcad.plm.basic.util.TyplmEntityBaseUtil;
import com.hustcad.plm.basic.util.TyplmLoggerUtil;
import com.hustcad.plm.caddocapi.service.TyplmCADDocumentService;
import com.hustcad.plm.pdm.access.model.dto.AccessBatchDTO;
import com.hustcad.plm.pdm.access.service.TyplmAccessJudgeService;
import com.hustcad.plm.pdm.audit.util.TyplmAuditLogUtil;
import com.hustcad.plm.pdm.baseline.service.TyplmBaseLineService;
import com.hustcad.plm.pdm.common.model.dto.hisearch.SearchPage;
import com.hustcad.plm.pdm.common.service.entity.TyplmEntityBaseService;
import com.hustcad.plm.pdm.common.service.search.TyplmCommonSearchService;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.container.model.dto.Product;
import com.hustcad.plm.pdm.container.service.ProductService;
import com.hustcad.plm.pdm.container.service.TyplmContainerService;
import com.hustcad.plm.pdm.doc.service.TyplmDocumentService;
import com.hustcad.plm.pdm.doc.vo.DocDetails;
import com.hustcad.plm.pdm.enumeration.service.TyplmLocalePropertyValueService;
import com.hustcad.plm.pdm.file.util.QueryDownloadDocUtil;
import com.hustcad.plm.pdm.flowbusiness.mapper.TyplmFlowObjectPackageCheckMapper;
import com.hustcad.plm.pdm.flowbusiness.mapper.TyplmFlowObjectPackageLinkMapper;
import com.hustcad.plm.pdm.flowbusiness.model.dto.PackageRefreshDTO;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObjectPackage;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObjectPackageLink;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowPackageCheckedObject;
import com.hustcad.plm.pdm.flowbusiness.model.entity.WorkFlowObjectPackage;
import com.hustcad.plm.pdm.flowbusiness.model.vo.FlowObjectStructuredParamVO;
import com.hustcad.plm.pdm.flowbusiness.model.vo.FlowObjectStructuredReturnVO;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmCheckCollectionObjService;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmFlowObjectPackageLinkService;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmFlowObjectPackageService;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmWorkFlowObjectPackageService;
import com.hustcad.plm.pdm.flowexpansion.model.entity.TypeWorkFlowRule;
import com.hustcad.plm.pdm.flowexpansion.model.entity.WorkFlowRelationEObj;
import com.hustcad.plm.pdm.flowexpansion.service.TyplmWorkFlowRelationService;
import com.hustcad.plm.pdm.flowexpansion.service.TyplmWorkFlowRuleService;
import com.hustcad.plm.pdm.form.model.vo.FormDataVO;
import com.hustcad.plm.pdm.form.service.TyplmFormDataService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleStageService;
import com.hustcad.plm.pdm.middle.partbom.service.TyplmPdmPartService;
import com.hustcad.plm.pdm.modeling.model.dto.TyplmGeneralOperationDTO;
import com.hustcad.plm.pdm.mpmlink.model.vo.TyplmProcessPlanVo;
import com.hustcad.plm.pdm.mpmlink.service.TyplmMpmCommonAdaptationService;
import com.hustcad.plm.pdm.mpmlink.service.TyplmMpmOperationAdaptationService;
import com.hustcad.plm.pdm.mpmlink.service.TyplmMpmProcessPlanAdaptationService;
import com.hustcad.plm.pdm.mpmlink.service.TyplmMpmWorkFlowAdaptationService;
import com.hustcad.plm.pdm.partbom.dto.CalculatePartRootDTO;
import com.hustcad.plm.pdm.partbom.dto.PartBomTree;
import com.hustcad.plm.pdm.partbom.query.PartLevelBomQuery;
import com.hustcad.plm.pdm.partbom.service.TyplmPartBomFlowObjectService;
import com.hustcad.plm.pdm.partbom.service.TyplmPartBomService;
import com.hustcad.plm.pdm.partbom.service.TyplmPartService;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.hustcad.plm.pdm.preference.util.TyplmPreferenceValueUtil;
import com.hustcad.plm.pdm.type.model.vo.TypeVueVO;
import com.hustcad.plm.pdm.type.service.TyplmTypeExtService;
import com.hustcad.plm.pdm.type.service.TyplmTypeMasterService;
import com.hustcad.plm.pdm.type.service.TyplmTypeService;
import com.hustcad.plm.pdm.user.model.dto.PdmUserDTO;
import com.hustcad.plm.pdm.user.service.TyplmDomainService;
import com.hustcad.plm.pdm.user.service.organization.PdmUserService;
import com.hustcad.plm.pdm.workflow.model.constant.ObjectHasFlowedEnum;
import com.hustcad.plm.pdm.workflow.model.constant.WorkFlowContainerStatusEnum;
import com.hustcad.plm.pdm.workflow.model.constant.WorkFlowErrorCodeEnum;
import com.hustcad.plm.pdm.workflow.model.dto.WorkFlowObjectDTO;
import com.hustcad.plm.pdm.workflow.model.entity.FlowTaskInfo;
import com.hustcad.plm.pdm.workflow.model.entity.RuFlowObject;
import com.hustcad.plm.pdm.workflow.model.entity.UserTaskDTO;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlow;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlowContainer;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlowContainerView;
import com.hustcad.plm.pdm.workflow.service.TyplmErrorMarkService;
import com.hustcad.plm.pdm.workflow.service.TyplmFlowCommonService;
import com.hustcad.plm.pdm.workflow.service.TyplmFlowContainerObjectService;
import com.hustcad.plm.pdm.workflow.service.TyplmFlowElementService;
import com.hustcad.plm.pdm.workflow.service.TyplmFlowHandlerService;
import com.hustcad.plm.pdm.workflow.service.TyplmFlowObjectTaskLinkService;
import com.hustcad.plm.pdm.workflow.service.TyplmRuFlowObjectService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowCommonViewService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowContainerInstanceService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowContainerService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowContainerViewService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowProcessService;
import com.hustcad.plm.pdm.workflow.service.TyplmWorkFlowRightControlService;
import com.hustcad.plm.pdm.workflow.util.TyplmWorkFlowUtil;
import com.ty.basic.common.ITyContained;
import com.ty.basic.common.ITyIterated;
import com.ty.basic.common.ITyLifeCycleManaged;
import com.ty.basic.common.ITyLockable;
import com.ty.basic.common.ITyTyped;
import com.ty.basic.common.IteratorEntity;
import com.ty.basic.constant.ContainerConstant;
import com.ty.basic.entity.CTyEntityBaseDO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.baseline.BaseLineDO;
import com.ty.basic.entity.cad.CADDocDO;
import com.ty.basic.entity.domain.DomainDO;
import com.ty.basic.entity.mpmlink.MPMOperationDO;
import com.ty.basic.entity.mpmlink.MPMProcessPlanDO;
import com.ty.basic.entity.type.TypeDO;
import com.ty.basic.entity.type.TypeMasterDO;
import com.ty.basic.entity.view.ViewDefDO;
import com.ty.basic.exception.message.SystemErrorCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.service.snow.SnowflakeIdComponent;
import com.ty.basic.session.RequestContext;
import com.ty.basic.session.TyAccountContext;
import com.ty.basic.util.EntityBaseUtil;
import com.ty.basic.util.TyEntityMapperUtil;
import com.ty.basic.util.TySpringBeanUtil;
import com.ty.basic.utils.ArgumentUtils;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.assertj.core.util.Lists;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

@Service
@RefreshScope
public class TyplmWorkFlowObjectPackageServiceImpl implements TyplmWorkFlowObjectPackageService {
    private static final Logger log = LoggerFactory.getLogger(TyplmWorkFlowObjectPackageServiceImpl.class);
    @Resource
    private TyplmMpmWorkFlowAdaptationService tymMpmWorkFlowAdaptationService;
    @Resource
    private TyplmFlowObjectPackageLinkService typlmFlowObjectPackageLinkService;
    @Resource
    private TyplmFlowObjectPackageService typlmFlowObjectPackageService;
    @Resource
    private TyplmWorkFlowContainerService typlmWorkFlowContainerService;
    @Resource
    private TyplmWorkFlowContainerViewService typlmWorkFlowContainerViewService;
    @Resource
    private TyplmWorkFlowRightControlService typlmWorkFlowRightControlService;
    @Resource
    private TyplmFlowElementService typlmFlowElementService;
    @Resource
    private ProductService productService;
    @Resource
    private TyplmPartBomService typlmPartBomService;
    @Resource
    private TyplmFlowCommonService typlmFlowCommonService;
    @Resource
    private TyplmLifecycleStageService typlmLifecycleStageService;
    @Resource
    private TyplmPartService typlmPartService;
    @Resource
    private TyplmPdmPartService typlmPdmPartService;
    @Resource
    private TyplmTypeService typlmTypeService;
    @Resource
    private TyplmDocumentService typlmDocumentService;
    @Resource
    private TyplmWorkFlowRelationService workFlowRelationService;
    @Resource
    private TyplmWorkFlowCommonViewService typlmWorkFlowCommonViewService;
    @Resource
    private TyplmFlowContainerObjectService typlmFlowContainerObjectService;
    @Resource
    private TyplmRuFlowObjectService typlmRuFlowObjectService;
    @Resource
    private TyplmFlowObjectTaskLinkService typlmFlowObjectTaskLinkService;
    @Resource
    private TyplmErrorMarkService errorMarkService;
    @Resource
    private TyplmFormDataService typlmFormDataService;
    @Resource
    private TyplmTypeMasterService typlmTypeMasterService;
    @Resource
    private TaskService taskService;
    @Resource
    private TyplmPreferenceValueUtil typlmPreferenceValueUtil;
    @Resource
    private TyplmAccessJudgeService typlmAccessJudgeService;
    @Resource
    private TyplmCheckCollectionObjService typlmCheckCollectionObjService;
    @Resource
    private TyplmLocalePropertyValueService typlmLocalePropertyValueService;
    @Resource
    private TyplmDomainService typlmDomainService;
    @Resource
    private TyplmContainerService typlmContainerService;
    @Resource
    private TyplmWorkFlowRuleService typlmWorkFlowRuleService;
    @Resource
    private TyplmPartBomFlowObjectService typlmPartBomFlowObjectService;
    @Resource
    private TyplmWorkFlowProcessService typlmWorkFlowProcessService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TyplmCADDocumentService typlmCADDocumentService;
    @Resource
    private SqlSessionFactory sqlSessionFactory;
    @Value("${workflow.package.object.target.status.need:true}")
    private boolean targetStatusNeed;
    @Value("${workFlow.typeName.config:}")
    private String typeNames;
    @Value("${batch.add.relation.state:}")
    private String state;
    @Resource
    @Lazy
    private TyplmBaseLineService typlmBaseLineService;
    @Resource
    private TyplmTypeExtService typlmTypeExtService;
    @Resource
    private PdmUserService pdmUserService;
    @Resource
    private TyplmFlowHandlerService typlmFlowHandlerService;
    @Resource
    private TyplmCommonSearchService typlmCommonSearchService;
    @Resource
    private TyplmFlowObjectPackageCheckMapper typlmFlowObjectPackageCheckMapper;
    @Resource
    private SnowflakeIdComponent snowflakeIdComponent;
    @Resource
    private TyplmEntityBaseService typlmEntityBaseService;
    private static final List<String> HANDLE_OTYPES = Arrays.asList("ty.inteplm.part.CTyPart", "ty.inteplm.cad.CTyCADDoc", "ty.inteplm.doc.CTyDoc");

    public WorkFlowObjectPackage batchAddCheckWorkFlowStart(PartLevelBomQuery levelBomQuery) {
        TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 方法入参levelBomQuery ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(levelBomQuery)});
        ArgumentUtils.checkArgumentEmpty(levelBomQuery, "父级零部件不存在");
        List<BaseObject> objList = new ArrayList();
        BaseObject parentPart = new BaseObject();
        WorkFlowObjectPackage workFlowContainer = new WorkFlowObjectPackage();
        TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 查询当前零部件信息及关联文档信息,满足条件的加入到objList start");
        PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(new BigInteger(levelBomQuery.getId()), (String)null);
        if (ObjectUtils.isNotEmpty(partDetailsVO)) {
            boolean parentFlag = this.isAddWorkFlow(partDetailsVO.getLifecycleState(), partDetailsVO.getCreatorName());
            if (parentFlag) {
                parentPart.setOid(new BigInteger(partDetailsVO.getOid()));
                parentPart.setOtype(partDetailsVO.getOtype());
                objList.add(parentPart);
            }

            this.addRelationDoc(partDetailsVO.getOid(), objList);
        }

        TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 查询当前零部件信息及关联文档信息,满足条件的加入到objList end, levelBomQuery <== 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        List<PartBomTree> partBomTrees = this.typlmPartBomService.bomStructureUnfold(levelBomQuery);
        TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 根据父零部件的id查询出所有子集 partBomTrees <== 【{}】", () -> new Object[]{JSONObject.toJSONString(partBomTrees)});
        if (ObjectUtils.isNotEmpty(partBomTrees)) {
            for(PartBomTree partBomTree : partBomTrees) {
                if (ObjectUtils.isNotEmpty(partBomTree.getChildren())) {
                    this.dealChildrenPart(partBomTree.getChildren(), objList);
                }
            }
        }

        if (ObjectUtils.isNotEmpty(objList)) {
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 校验对象列表是否能启动流程 start");
            workFlowContainer = this.checkObjListEnableStart(objList, (BigInteger)null, (String)null);
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 校验对象列表是否能启动流程 end");
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 生成流程容器信息 start");
            this.typlmWorkFlowContainerService.buildWorkFlowContainer(workFlowContainer);
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 生成流程容器信息 end");
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 生成空流程视图 start");
            this.typlmWorkFlowContainerViewService.buildWorkContainerView(workFlowContainer);
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 生成空流程视图 end");
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 从redis获取对应流程节点的处理人 start");
            this.typlmFlowCommonService.buildRecentFlowUsers(workFlowContainer);
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 从redis获取对应流程节点的处理人 end");
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 从redis获取对应流程模板的管理者和监控者信息 start");
            this.typlmFlowCommonService.buildRecentFlowManageAndSupervisor(workFlowContainer);
            TyplmLoggerUtil.debug(log, () -> "batchAddCheckWorkFlowStart 从redis获取对应流程模板的管理者和监控者信息 end");
            workFlowContainer.setTargetStatusNeed(this.targetStatusNeed);
        }

        return workFlowContainer;
    }

    public WorkFlowObjectPackage checkWorkFlowStartRules(List<BaseObject> objList, BigInteger containerOid, String containerOtype) {
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 方法入参objList ==> 【{}】; containerOid ==> 【{}】; containerOtype ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(containerOid), containerOtype});
        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 获取到的配置workFlow.typeName.config的值typeNames <== 【{}】", () -> new Object[]{this.typeNames});
        List<String> list;
        if (StringUtils.isBlank(this.typeNames)) {
            list = ListUtils.EMPTY_LIST;
        } else {
            list = Arrays.asList(this.typeNames.split(","));
        }

        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 获取配置中的类型名称集合list ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(list)});
        List<BaseObject> baseObjects = new CopyOnWriteArrayList();
        if (ObjectUtils.isNotEmpty(list)) {
            Map<String, List<BaseObject>> objMap = (Map)objList.stream().collect(Collectors.groupingBy(IdentifierEntity::getOtype));
            objMap.entrySet().stream().forEach((entry) -> {
                String otype = (String)entry.getKey();
                if (HANDLE_OTYPES.contains(otype)) {
                    List<String> oidList = (List)((List<BaseObject>)entry.getValue()).stream().map((baseObject) -> baseObject.getOid().toString()).collect(Collectors.toList());
                    List<CTyEntityBaseDO> entityList = CommonUtil.getEntitys(otype, oidList);
                    Map<String, Object> requestContext = RequestContext.currentContext();
                    entityList.parallelStream().forEach((item) -> {
                        RequestContext.attachContext(requestContext);
                        if (item instanceof ITyTyped) {
                            BigInteger typeOid = ((ITyTyped)item).getTypeoid();
                            TypeDO typeDO = this.typlmTypeService.queryTypeByOID(typeOid);
                            if (typeDO != null) {
                                List<BigInteger> typeMasterOidList = new ArrayList();
                                typeMasterOidList.add(typeDO.getMasteredoid());
                                List<TypeMasterDO> typeMasterDOList = this.typlmTypeMasterService.queryTypeMasterByOIDS(typeMasterOidList);
                                if (!CollUtil.isEmpty(typeMasterDOList)) {
                                    String displayName = ((TypeMasterDO)typeMasterDOList.get(0)).getDisplayname();
                                    if (list.contains(displayName)) {
                                        BigInteger itemOid = item.getOid();
                                        if ("ty.inteplm.part.CTyPart".equals(otype)) {
                                            this.addRelationDoc(itemOid.toString(), baseObjects, false);
                                        } else {
                                            List<PartDetailsVO> partDetailsVOS = this.typlmDocumentService.queryDocDescribeLinkPartByDoc(itemOid, otype);
                                            if (ObjectUtils.isNotEmpty(partDetailsVOS)) {
                                                for(PartDetailsVO partDetailsVO : partDetailsVOS) {
                                                    BaseObject part = new BaseObject();
                                                    part.setOid(new BigInteger(partDetailsVO.getOid()));
                                                    part.setOtype(partDetailsVO.getOtype());
                                                    part.setBranchId(BigInteger.valueOf(3L));
                                                    baseObjects.add(part);
                                                }
                                            }
                                        }

                                    }
                                }
                            }
                        }
                    });
                }
            });
        }

        objList.addAll(baseObjects);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 校验对象是否是最新大版本的最新小版本 start");
        this.checkObjectLatestVersion(objList);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 校验对象是否是最新大版本的最新小版本 end");
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 校验对象列表是否能启动流程 start");
        WorkFlowObjectPackage workFlowContainer = this.checkObjListEnableStart(objList, containerOid, containerOtype);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 校验对象列表是否能启动流程 end");
        List<String> normalContainerOtype = ContainerConstant.getNormalContainerOtype();
        Map<String, String> normalContainerOtypeMap = (Map)normalContainerOtype.stream().collect(Collectors.toMap(String::toLowerCase, (s) -> s));
        if (normalContainerOtypeMap.containsKey(containerOtype)) {
            workFlowContainer.setContainerOtype((String)normalContainerOtypeMap.get(containerOtype));
        }

        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 生成新流程容器 start");
        this.typlmWorkFlowContainerService.buildWorkFlowContainer(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 生成新流程容器 end");
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 生成空流程视图 start");
        this.typlmWorkFlowContainerViewService.buildWorkContainerView(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 生成空流程视图 end");
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 从redis获取对应流程节点的处理人 start");
        this.typlmFlowCommonService.buildRecentFlowUsers(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 从redis获取对应流程节点的处理人 end");
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 从redis获取对应流程模板的管理者和监控者信息 start");
        this.typlmFlowCommonService.buildRecentFlowManageAndSupervisor(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "checkWorkFlowStartRules 从redis获取对应流程模板的管理者和监控者信息 end");
        workFlowContainer.setTargetStatusNeed(this.targetStatusNeed);
        return workFlowContainer;
    }

    private void checkObjectLatestVersion(List<BaseObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "checkObjectLatestVersion 方法入参objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        List<CTyEntityBaseDO> baseDOList = new ArrayList();
        objList.forEach((info) -> {
            CTyEntityBaseDO baseDO = new CTyEntityBaseDO();
            baseDO.setOid(info.getOid());
            baseDO.setOtype(info.getOtype());
            baseDOList.add(baseDO);
        });
        this.typlmCheckCollectionObjService.checkCollectObjMajorAndLatestVersion(baseDOList);
    }

    public void setMasterIdAndLifeCycleStage(FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "setMasterIdAndLifeCycleStage 方法入参flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject)});
        BigInteger objId = flowObject.getRefObjectOid();
        String objType = flowObject.getRefObjectOtype();
        TyplmLoggerUtil.debug(log, () -> "setMasterIdAndLifeCycleStage 关联对象的类型 objType ==> 【{}】", () -> new Object[]{objType});
        switch (objType) {
            case "ty.inteplm.part.CTyPart":
                this.setPartInfo(flowObject, objId, objType);
                break;
            case "ty.inteplm.cad.CTyCADDoc":
            case "ty.inteplm.doc.CTyDoc":
                this.setDocInfo(flowObject, objId, objType);
                break;
            case "ty.inteplm.mpm.CTyMPMOperation":
                this.setOperationInfo(flowObject);
                break;
            case "ty.inteplm.mpm.CTyMPMProcessPlan":
                this.setProcessPlanInfo(flowObject);
                break;
            case "ty.inteplm.form.CTyFormData":
                this.setFormDataInfo(flowObject, objId);
                break;
            default:
                throw WorkFlowErrorCodeEnum.NOT_SUPPORT_TYPE.getException(new Object[]{objType});
        }

    }

    public List<FlowObject> addCheckWorkFlowStart(List<BaseObject> objList, BigInteger workFlowContainerId) {
        return this.addCheckWorkFlowStart(objList, workFlowContainerId, true);
    }

    public List<FlowObject> addCheckWorkFlowStart(List<BaseObject> objList, BigInteger workFlowContainerId, boolean addRelationObj) {
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 方法入参objList ==> 【{}】; workFlowContainerId ==> 【{}】; addRelationObj ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(workFlowContainerId), JSONObject.toJSONString(addRelationObj)});
        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        List<BaseObject> newObjList = new CopyOnWriteArrayList();
        if (addRelationObj) {
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 添加相关对象 start");
            this.addRelationObj(objList, newObjList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 添加相关对象 end,添加结果newObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(newObjList)});
        } else {
            newObjList.addAll(objList);
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 校验对象列表是否能启动流程 start");
        List<FlowObject> flowObjectList = this.addCheckObjListEnableStart(newObjList, workFlowContainerId);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 校验对象列表是否能启动流程 end,校验结果flowObjectList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList)});
        List<WorkFlowRelationEObj.RelationRequestEObj> relationRequestList = new ArrayList();

        for(FlowObject flowObject : flowObjectList) {
            WorkFlowRelationEObj workFlowRelationEObj = new WorkFlowRelationEObj();
            WorkFlowRelationEObj.RelationRequestEObj one = workFlowRelationEObj.getInnerInstance(flowObject.getMasterId(), flowObject.getLifeCycleStageKey());
            relationRequestList.add(one);
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 根据RelationRequestEObj列表（类型masterId和生命周期阶段查询绑定的流程模板的交集） start");
        PageInfo<WorkFlow> workFlowList = this.workFlowRelationService.queryIntersectionWorkFlows(relationRequestList, (SearchPage)null);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 根据RelationRequestEObj列表（类型masterId和生命周期阶段查询绑定的流程模板的交集） end ,查询结果workFlowList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowList)});
        if (workFlowList != null && workFlowList.getList() != null && !workFlowList.getList().isEmpty()) {
            return flowObjectList;
        } else {
            throw WorkFlowErrorCodeEnum.HAS_NO_SAME_WORK_FLOW_TEMPLATE.getException(new Object[0]);
        }
    }

    public List<FlowObject> addCheckWorkFlowStart(List<BaseObject> objList, BigInteger workflowId, BigInteger workFlowContainerId, boolean addRelationObj) {
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 方法入参objList ==> 【{}】; workflowId ==> 【{}】;workFlowContainerId ==> 【{}】; addRelationObj ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(workflowId), JSONObject.toJSONString(workFlowContainerId), JSONObject.toJSONString(addRelationObj)});
        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        List<BaseObject> newObjList = new CopyOnWriteArrayList();
        if (addRelationObj) {
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 添加相关对象 start");
            this.addRelationObj(objList, newObjList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 添加相关对象 end,添加结果newObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(newObjList)});
        } else {
            newObjList.addAll(objList);
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 校验对象列表是否能启动流程 start");
        List<FlowObject> flowObjectList = this.addCheckObjListEnableStart(newObjList, workFlowContainerId);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStart 校验对象列表是否能启动流程 end,校验结果flowObjectList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList)});
        this.checkFlowObjectContainsWorkFlow(flowObjectList, workflowId);
        return flowObjectList;
    }

    public FlowObjectStructuredReturnVO addCheckWorkFlowStartCommon(FlowObjectStructuredParamVO flowObjectStructuredParamVO) {
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 方法入参flowObjectStructuredParamVO ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectStructuredParamVO)});
        ArgumentUtils.checkArgumentNull(flowObjectStructuredParamVO, "flowObjectStructuredParamVO");
        BigInteger workFlowId = flowObjectStructuredParamVO.getWorkFlowId();
        BigInteger workFlowContainerId = flowObjectStructuredParamVO.getWorkFlowContainerId();
        List<BaseObject> objList = flowObjectStructuredParamVO.getObjList();
        List<FlowObject> oirAllObjList = flowObjectStructuredParamVO.getOirAllObjList();
        ArgumentUtils.checkArgumentNull(workFlowId, "workFlowId");
        ArgumentUtils.checkArgumentNull(objList, "objList");
        List<BigInteger> cadIdList = (List)objList.stream().filter((item) -> "ty.inteplm.cad.CTyCADDoc".equals(item.getOtype())).map((item) -> item.getOid()).collect(Collectors.toList());
        List<CADDocDO> cadDocDOS = this.typlmCADDocumentService.queryFamilyObjectByCadIdList(cadIdList);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 查询cad的族表成员 cadDocDOS <== 【{}】;", () -> new Object[]{JSONObject.toJSONString(cadDocDOS)});
        if (CollUtil.isNotEmpty(cadDocDOS)) {
            cadDocDOS.stream().forEach((item) -> {
                BaseObject obj = new BaseObject();
                obj.setOid(item.getOid());
                obj.setOtype(item.getOtype());
                objList.add(obj);
            });
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 先校验能否添加 start");
        List<FlowObject> checklist = this.addCheckWorkFlowStart(objList, workFlowId, workFlowContainerId, true);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 先校验能否添加 start,校验添加结果checklist ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(checklist)});
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 通过过滤取工艺对象合非工艺对象集合 start");
        List<FlowObject> mpmObjectList = (List)checklist.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
        List<FlowObject> otherObjectList = new ArrayList();
        otherObjectList.addAll(checklist);
        if (!CollectionUtils.isEmpty(mpmObjectList)) {
            otherObjectList.removeAll(mpmObjectList);
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 通过 过滤取工艺对象合非工艺对象集合 end");
        List<FlowObject> oriMpmObjectList = (List)oirAllObjList.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
        otherObjectList.addAll(oirAllObjList);
        if (!CollectionUtils.isEmpty(oriMpmObjectList)) {
            otherObjectList.removeAll(oriMpmObjectList);
        }

        FlowObjectStructuredReturnVO flowObjectStructuredReturnVO = new FlowObjectStructuredReturnVO();
        List<FlowObject> returnList = new ArrayList();
        List<FlowObject> returnRootList = new ArrayList();
        List<FlowObject> allFlowObjectList = new ArrayList();
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对非工艺对象算根 start");
        if (!CollectionUtils.isEmpty(otherObjectList)) {
            this.partCalcRootNode(otherObjectList);
            allFlowObjectList.addAll(otherObjectList);
        }

        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对非工艺对象算根 end");
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对工艺对象算根 start");
        if (!CollectionUtils.isEmpty(oriMpmObjectList)) {
            mpmObjectList.addAll(oriMpmObjectList);
        }

        this.tymMpmWorkFlowAdaptationService.batchSetMpmObjTypeMarkFlag(mpmObjectList);
        allFlowObjectList.addAll(mpmObjectList);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对工艺对象算根 end");
        this.handleIsRootData(allFlowObjectList, returnList, returnRootList);
        returnList.removeAll(oirAllObjList);
        flowObjectStructuredReturnVO.setObjList(returnList);
        flowObjectStructuredReturnVO.setRootList(returnRootList);
        if (CollUtil.isNotEmpty(flowObjectStructuredParamVO.getColumns())) {
            List<FlowObject> objects = new ArrayList(returnList);
            objects.addAll(returnRootList);
            this.typlmCommonSearchService.dealFlowObjectDynamicColumns(flowObjectStructuredParamVO.getColumns(), objects);
        }

        if (Objects.isNull(workFlowContainerId)) {
            return flowObjectStructuredReturnVO;
        } else {
            List<BigInteger> collect = (List)objList.stream().map(IdentifierEntity::getOid).collect(Collectors.toList());
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对于流程容器id存在的数据做实时入库处理（将带添加的对象实时入库） start");
            List<FlowObject> inDataList = (List)allFlowObjectList.stream().filter((item) -> collect.contains(item.getRefObjectOid())).collect(Collectors.toList());
            this.flowObjectIntoData(workFlowContainerId, inDataList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 对于流程容器id存在的数据做实时入库处理（将带添加的对象实时入库） end");
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartCommon 返回值flowObjectStructuredReturnVO ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(flowObjectStructuredReturnVO)});
            return flowObjectStructuredReturnVO;
        }
    }

    public List<FlowObject> refreshFlowObjectList(PackageRefreshDTO packageRefresh) {
        TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 方法入参packageRefresh ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(packageRefresh)});
        IdentifierEntity flowPackage = packageRefresh.getFlowPackage();
        if (flowPackage != null && !BigInteger.ZERO.equals(flowPackage.getOid())) {
            TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程包不为空的情况直接从数据库获取数据 start");
            List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(packageRefresh);
            if (TyAccountContext.isDebug()) {
                log.info("refreshFlowObjectList 流程包不为空的情况直接从数据库获取结果flowObjectList ==> 【{}】", JSONObject.toJSONString(flowObjectList));
            }

            String taskId = packageRefresh.getTaskId();
            if (StringUtils.isNotBlank(taskId)) {
                Task task = (Task)((TaskQuery)this.taskService.createTaskQuery().taskId(taskId)).singleResult();
                if (task != null) {
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程中的情况，根据当前当前任务节点是否分配内容属性判断flowObjectList是否需要过滤 start");
                    String processInstanceId = task.getProcessInstanceId();
                    WorkFlowContainer workFlowContainer = this.typlmWorkFlowContainerService.getWorkFlowContainerByFlowableProcessId(processInstanceId);
                    FlowTaskInfo flowTaskInfo = this.typlmWorkFlowProcessService.getFlowTaskInfo(task, workFlowContainer);
                    flowObjectList = this.filterFlowObjectList(flowObjectList, flowTaskInfo);
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程中的情况，根据当前当前任务节点是否分配内容属性判断flowObjectList是否需要过滤 end");
                    this.tymMpmWorkFlowAdaptationService.batchBuildMpmStructure(flowObjectList);
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程对象要根据逻辑算零件根 start");
                    this.handlePartRoot(flowObjectList);
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程对象要根据逻辑算零件根 end");
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 根据流程重置错误标记信息 start");
                    this.errorMarkService.resetErrorMarkInfoByWorkFlow(flowTaskInfo, flowObjectList);
                    TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 根据流程重置错误标记信息 end");
                }
            }

            if (CollUtil.isNotEmpty(flowObjectList)) {
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 设置基线编码展示信息 start");
                this.setBaseLineObject(flowObjectList);
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 设置基线编码展示信息 end");
            }

            TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程包不为空的情况直接从数据库获取数据 end");
            if (CollUtil.isNotEmpty(packageRefresh.getColumns())) {
                this.typlmCommonSearchService.dealFlowObjectDynamicColumns(packageRefresh.getColumns(), flowObjectList);
            }

            return flowObjectList;
        } else {
            List<FlowObject> flowObjectList = new CopyOnWriteArrayList();
            List<FlowObject> paramList = packageRefresh.getFlowObjectList();
            if (!CollectionUtils.isEmpty(paramList)) {
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 没有对象的时候则是新建的刷新 start");
                Map<String, Collection<BigInteger>> otypeBranchIdMap = new HashMap();
                List<BaseObject> objList = new ArrayList();

                for(FlowObject flowObject : paramList) {
                    BigInteger branchId = flowObject.getBranchId();
                    if (!EntityBaseUtil.isEmptyOid(branchId)) {
                        Collection<BigInteger> collection = (Collection)otypeBranchIdMap.computeIfAbsent(flowObject.getRefObjectOtype(), (k) -> new HashSet());
                        collection.add(branchId);
                    } else {
                        BaseObject baseObject = new BaseObject(flowObject.getRefObjectOid(), flowObject.getRefObjectOtype());
                        objList.add(baseObject);
                    }
                }

                if (!CollectionUtils.isEmpty(otypeBranchIdMap)) {
                    BigInteger userOid = CommonUtil.getUserOid();
                    boolean userEmptyFlag = !EntityBaseUtil.isEmptyOid(userOid);

                    for(Map.Entry<String, Collection<BigInteger>> entry : otypeBranchIdMap.entrySet()) {
                        String otype = (String)entry.getKey();
                        Collection<BigInteger> branchIdList = (Collection)entry.getValue();
                        List<CTyEntityBaseDO> entityBaseDOList = CommonUtil.getLastEntityByBranchIdIgnoreNotExist(otype, branchIdList);
                        Map<BigInteger, CTyEntityBaseDO> branchEntityMap = new HashMap();

                        for(CTyEntityBaseDO cTyEntityBaseDO : entityBaseDOList) {
                            if (cTyEntityBaseDO instanceof IteratorEntity) {
                                IteratorEntity obj = (IteratorEntity)cTyEntityBaseDO;
                                BigInteger branchid = obj.getBranchid();
                                CTyEntityBaseDO baseDO = (CTyEntityBaseDO)branchEntityMap.get(branchid);
                                if ("wrk".equals(obj.getLockstateinfo()) && userEmptyFlag && userOid.equals(obj.getLockeroid()) || baseDO == null) {
                                    branchEntityMap.put(branchid, cTyEntityBaseDO);
                                }
                            }
                        }

                        Collection<CTyEntityBaseDO> entityList = branchEntityMap.values();
                        Map<String, Object> requestContext = RequestContext.currentContext();
                        entityList.parallelStream().forEach((entity) -> {
                            RequestContext.attachContext(requestContext);
                            FlowObject flowObject = new FlowObject();
                            BigInteger refObjectOid = entity.getOid();
                            String refObjectOtype = entity.getOtype();
                            String refObjectName = entity.getName();
                            List<BigInteger> list = new ArrayList();
                            if (entity instanceof ITyContained) {
                                ITyContained iTyContained = (ITyContained)entity;
                                flowObject.setContainerOid(iTyContained.getContaineroid());
                                flowObject.setContainerOtype(iTyContained.getContainerotype());
                            }

                            this.handleTyped(entity, flowObject, list);
                            refObjectName = this.setProcessObject(flowObject, entity, refObjectOtype, refObjectName);
                            flowObject.setRefObjectOid(refObjectOid);
                            flowObject.setRefObjectOtype(refObjectOtype);
                            flowObject.setRefObjectName(refObjectName);
                            this.handleLifeCycleManaged(entity, flowObject);
                            if (entity instanceof IteratorEntity) {
                                IteratorEntity obj = (IteratorEntity)entity;
                                flowObject.setMasteredoid(obj.getMasteredoid());
                                flowObject.setBranchId(obj.getBranchid());
                                this.typlmFlowObjectPackageLinkService.setFlowObjectIteratorInfo(flowObject, obj);
                            }

                            flowObjectList.add(flowObject);
                        });
                    }
                }

                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 将基础对象转换成FlowObject start");
                List<FlowObject> otherFlowObjectList = this.baseObjectToFlowObject(objList, false);
                flowObjectList.addAll(otherFlowObjectList);
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 将基础对象转换成FlowObject end");
                this.tymMpmWorkFlowAdaptationService.batchBuildMpmStructure(flowObjectList);
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程对象要根据逻辑算零件根 start");
                this.handlePartRoot(flowObjectList);
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 流程对象要根据逻辑算零件根 end");
            }

            if (flowObjectList != null && CollUtil.isNotEmpty(flowObjectList)) {
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 设置基线编码展示信息 start");
                this.setBaseLineObject(flowObjectList);
                TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 设置基线编码展示信息 end");
            }

            TyplmLoggerUtil.debug(log, () -> "refreshFlowObjectList 没有对象的时候则是新建的刷新 end");
            if (CollUtil.isNotEmpty(packageRefresh.getColumns())) {
                this.typlmCommonSearchService.dealFlowObjectDynamicColumns(packageRefresh.getColumns(), flowObjectList);
            }

            return flowObjectList;
        }
    }

    public FlowObjectStructuredReturnVO removeCheckWorkFlowStartCommon(FlowObjectStructuredParamVO flowObjectStructuredParamVO) {
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 方法入参flowObjectStructuredParamVO ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectStructuredParamVO)});
        ArgumentUtils.checkArgumentNull(flowObjectStructuredParamVO, "flowObjectStructuredParamVO");
        BigInteger workFlowContainerId = flowObjectStructuredParamVO.getWorkFlowContainerId();
        List<FlowObject> removeObjList = flowObjectStructuredParamVO.getRemoveObjList();
        List<FlowObject> allObjList = flowObjectStructuredParamVO.getAllObjList();
        ArgumentUtils.checkArgumentEmpty(removeObjList, "removeObjList");
        ArgumentUtils.checkArgumentEmpty(allObjList, "allObjList");
        List<FlowObject> mpmFlowObjectList = (List)allObjList.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
        List<BigInteger> cadIdList = (List)removeObjList.stream().filter((item) -> "ty.inteplm.cad.CTyCADDoc".equals(item.getRefObjectOtype())).map(FlowObjectPackageLink::getRefObjectOid).collect(Collectors.toList());
        List<FlowObject> returnList = new ArrayList();
        Map<BigInteger, FlowObject> allObjMap = (Map)allObjList.stream().collect(Collectors.toMap(FlowObjectPackageLink::getRefObjectOid, Function.identity(), (a, b) -> b));
        removeObjList.forEach((removeObj) -> {
            if (Objects.isNull(removeObj.getOid())) {
                FlowObject object = (FlowObject)allObjMap.get(removeObj.getRefObjectOid());
                removeObj.setOid(object.getOid());
            }

        });
        List<CADDocDO> cadDocDOS = this.typlmCADDocumentService.queryFamilyObjectByCadIdList(cadIdList);
        if (CollUtil.isNotEmpty(cadDocDOS)) {
            cadDocDOS.stream().forEach((item) -> {
                FlowObject flowObject = (FlowObject)allObjMap.get(item.getOid());
                if (flowObject != null) {
                    removeObjList.add(flowObject);
                }

            });
        }

        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 先移除所有勾选的数据 start");

        for(FlowObject flowObject : removeObjList) {
            BigInteger branchId = flowObject.getBranchId();
            allObjList.removeIf((item) -> item.getRefObjectOid().equals(flowObject.getRefObjectOid()) || Objects.nonNull(item.getBranchId()) && item.getBranchId().equals(branchId));
        }

        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 先移除所有勾选的数据 end");
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 去除工艺部分的数据 start");
        allObjList.removeAll(mpmFlowObjectList);
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 去除工艺部分的数据 end");
        returnList.addAll(removeObjList);
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 对removeList进行过滤 start");
        List<FlowObject> mpmRemoveList = (List)removeObjList.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 对removeList进行过滤 end");
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺转化为IdentifierEntity start");
        List<IdentifierEntity> identifierEntitysMpm = (List)mpmRemoveList.stream().map((item) -> new IdentifierEntity(item.getRefObjectOid(), item.getRefObjectOtype())).collect(Collectors.toList());
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺转化为IdentifierEntity end");
        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺的需要递归处理 start");
        List<IdentifierEntity> deleteChildListRecurrence = this.tymMpmWorkFlowAdaptationService.getDeleteChildListRecurrence(identifierEntitysMpm);
        Map<BigInteger, FlowObject> mpmMap = (Map)mpmFlowObjectList.stream().collect(Collectors.toMap(FlowObjectPackageLink::getRefObjectOid, (item) -> item, (i, j) -> i));
        if (CollUtil.isNotEmpty(deleteChildListRecurrence)) {
            for(IdentifierEntity identifierEntity : deleteChildListRecurrence) {
                FlowObject flowObject = (FlowObject)mpmMap.get(identifierEntity.getOid());
                if (flowObject != null) {
                    mpmFlowObjectList.remove(flowObject);
                    if (!returnList.contains(flowObject)) {
                        returnList.add(flowObject);
                    }
                }
            }
        }

        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺的需要递归处理 end");
        FlowObjectStructuredReturnVO flowObjectStructuredReturnVO = new FlowObjectStructuredReturnVO();
        List<FlowObject> returnRootList = new ArrayList();
        List<FlowObject> finallyFlowObjectList = new ArrayList();
        if (CollUtil.isNotEmpty(mpmFlowObjectList)) {
            TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺对象算根 start");
            this.tymMpmWorkFlowAdaptationService.batchSetMpmObjTypeMarkFlag(mpmFlowObjectList);
            finallyFlowObjectList.addAll(mpmFlowObjectList);
            TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 工艺对象算根 end");
        }

        if (CollUtil.isNotEmpty(allObjList)) {
            TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 非工艺对象算根 start");
            this.partCalcRootNode(allObjList);
            finallyFlowObjectList.addAll(allObjList);
            TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 非工艺对象算根 end");
        }

        this.handleIsRootData(finallyFlowObjectList, new ArrayList(), returnRootList);
        flowObjectStructuredReturnVO.setObjList(returnList);
        flowObjectStructuredReturnVO.setRootList(returnRootList);
        if (!TyplmEntityBaseUtil.isEmptyOid(workFlowContainerId) && !CollectionUtils.isEmpty(returnList)) {
            WorkFlowContainer workFlowContainer = (WorkFlowContainer)this.typlmWorkFlowContainerService.selectOneByOid(workFlowContainerId);
            if (workFlowContainer == null) {
                return flowObjectStructuredReturnVO;
            } else {
                if (!CollectionUtils.isEmpty(returnList)) {
                    TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 对于流程容器id存在的数据做实时入库处理 start");
                    Set<BigInteger> collect = (Set)returnList.stream().map(FlowObjectPackageLink::getOid).collect(Collectors.toSet());
                    this.typlmFlowObjectPackageLinkService.delete(collect);
                    TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 对于流程容器id存在的数据做实时入库处理 end");
                }

                String flowableProcessId = workFlowContainer.getFlowableProcessId();
                if (StringUtils.isBlank(flowableProcessId)) {
                    this.handleRuFlowObject(returnList, workFlowContainer.getOid(), workFlowContainer.getOtype());
                    return flowObjectStructuredReturnVO;
                } else {
                    ProcessInstance processInstance = (ProcessInstance)this.runtimeService.createProcessInstanceQuery().processInstanceId(flowableProcessId).singleResult();
                    if (processInstance == null) {
                        return flowObjectStructuredReturnVO;
                    } else {
                        String superExecutionId = processInstance.getSuperExecutionId();
                        if (StringUtils.isNotBlank(superExecutionId)) {
                            workFlowContainer = this.findRootWorkFlowContainer(workFlowContainer);
                        }

                        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 处理流程中对象数据handleRuFlowObject start");
                        this.handleRuFlowObject(returnList, workFlowContainer.getOid(), workFlowContainer.getOtype());
                        TyplmLoggerUtil.debug(log, () -> "removeCheckWorkFlowStartCommon 处理流程中对象数据handleRuFlowObject end");
                        return flowObjectStructuredReturnVO;
                    }
                }
            }
        } else {
            return flowObjectStructuredReturnVO;
        }
    }

    private void handleRuFlowObject(List<FlowObject> returnList, BigInteger oid, String otype) {
        TyplmLoggerUtil.debug(log, () -> "handleRuFlowObject 方法入参returnList ==> 【{}】; oid ==> 【{}】; otype ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(returnList), JSONObject.toJSONString(oid), otype});
        List<BigInteger> objIds = new ArrayList();
        List<BigInteger> objBranchIds = new ArrayList();

        for(FlowObject flowObject : returnList) {
            BigInteger refObjectOid = flowObject.getRefObjectOid();
            if (!TyplmEntityBaseUtil.isEmptyOid(refObjectOid)) {
                objIds.add(refObjectOid);
            }

            BigInteger branchId = flowObject.getBranchId();
            if (!TyplmEntityBaseUtil.isEmptyOid(refObjectOid)) {
                objBranchIds.add(branchId);
            }
        }

        this.typlmRuFlowObjectService.deleteRuFlowObjectByObjIds(oid, otype, objIds);
        this.typlmRuFlowObjectService.deleteRuFlowObjectBybranchIds(oid, otype, objBranchIds);
    }

    private void handleIsRootData(List<FlowObject> paramList, List<FlowObject> returnList, List<FlowObject> returnRootList) {
        List<FlowObject> isRootList = (List)paramList.stream().filter((item) -> 1 == (item.getTypeMarkFlag() == null ? 0 : item.getTypeMarkFlag())).collect(Collectors.toList());
        List<FlowObject> notRootList = (List)paramList.stream().filter((item) -> 1 != (item.getTypeMarkFlag() == null ? 0 : item.getTypeMarkFlag())).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(notRootList)) {
            returnList.addAll(notRootList);
        }

        if (!CollectionUtils.isEmpty(isRootList)) {
            returnRootList.addAll(isRootList);
        }

    }

    private List<FlowObject> getFlowObject(List<FlowObject> cloneMpmObjectRootList, List<FlowObject> rootChangeList) {
        List<FlowObject> mpmRootList = new ArrayList();
        if (!CollectionUtils.isEmpty(cloneMpmObjectRootList)) {
            if (CollectionUtils.isEmpty(rootChangeList)) {
                mpmRootList.addAll(cloneMpmObjectRootList);
            } else {
                List<BigInteger> refList = (List)rootChangeList.stream().map(FlowObjectPackageLink::getRefObjectOid).collect(Collectors.toList());

                for(FlowObject flowObject : cloneMpmObjectRootList) {
                    if (refList.contains(flowObject.getRefObjectOid())) {
                        flowObject.setTypeMarkFlag(flowObject.getTypeMarkFlag() == 1 ? 0 : 1);
                    }
                }

                mpmRootList.addAll(cloneMpmObjectRootList);
            }
        }

        return mpmRootList;
    }

    private void flowObjectIntoData(BigInteger workFlowContainerId, List<FlowObject> returnList) {
        TyplmLoggerUtil.debug(log, () -> "flowObjectIntoData 方法入参workFlowContainerId ==> 【{}】; returnList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerId), JSONObject.toJSONString(returnList)});
        if (!CollectionUtils.isEmpty(returnList)) {
            WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)this.typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(workFlowContainerId);
            List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
            if (flowObjectList == null) {
                flowObjectList = new ArrayList();
            }

            flowObjectList.addAll(returnList);
            this.updateObjectLink(workFlowObjectPackage, flowObjectList);
            this.updateContainerSaveFlowObjectStatus(workFlowObjectPackage);
        }
    }

    private void partCalcRootNode(List<FlowObject> flowObjects) {
        TyplmLoggerUtil.debug(log, () -> "partCalcRootNode 方法入参flowObjects ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjects)});
        if (!CollectionUtils.isEmpty(flowObjects)) {
            List<FlowObject> partList = (List)flowObjects.stream().filter((item) -> StringUtils.equals("ty.inteplm.part.CTyPart", item.getRefObjectOtype())).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(partList)) {
                CalculatePartRootDTO calculatePartRootDTO = new CalculatePartRootDTO();
                List<BigInteger> partbigIntegerList = (List)partList.stream().map(FlowObjectPackageLink::getRefObjectOid).collect(Collectors.toList());
                calculatePartRootDTO.setNowPartList(partbigIntegerList);
                List<BigInteger> bigIntegers = this.typlmPartBomFlowObjectService.batchCalculatePartRootNode(calculatePartRootDTO);
                if (!CollectionUtils.isEmpty(bigIntegers)) {
                    for(FlowObject flowObject : flowObjects) {
                        flowObject.setObjHasFlowStatus(ObjectHasFlowedEnum.IN_THIS_PROCESS.getCode());
                        flowObject.setHasChildren(false);
                        if (bigIntegers.contains(flowObject.getRefObjectOid())) {
                            flowObject.setTypeMarkFlag(1);
                        } else {
                            flowObject.setTypeMarkFlag(0);
                        }
                    }

                } else {
                    for(FlowObject flowObject : flowObjects) {
                        flowObject.setTypeMarkFlag(0);
                        flowObject.setHasChildren(false);
                        flowObject.setObjHasFlowStatus(ObjectHasFlowedEnum.IN_THIS_PROCESS.getCode());
                    }

                }
            } else {
                for(FlowObject flowObject : flowObjects) {
                    flowObject.setTypeMarkFlag(0);
                    flowObject.setHasChildren(false);
                    flowObject.setObjHasFlowStatus(ObjectHasFlowedEnum.IN_THIS_PROCESS.getCode());
                }

            }
        }
    }

    public FlowPackageCheckedObject addCheckWorkFlowStartNoThrow(List<BaseObject> objList, BigInteger workflowId, BigInteger workFlowContainerId) {
        if (TyAccountContext.isDebug()) {
            log.info("addCheckWorkFlowStartNoThrow 方法入参objList ==> 【{}】; workflowId ==> 【{}】; workFlowContainerId ==> 【{}】", new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(workflowId), JSONObject.toJSONString(workFlowContainerId)});
        }

        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        ArgumentUtils.checkArgumentEmpty(workflowId, "流程模板");
        objList = this.filterObjList(objList, workFlowContainerId);
        Map<IdentifierEntity, BaseObject> baseObjectMap = (Map)objList.stream().collect(Collectors.toMap((item) -> new IdentifierEntity(item.getOid(), item.getOtype()), (item) -> item, (i, j) -> i));
        List<IdentifierEntity> identityList = new ArrayList(baseObjectMap.keySet());
        Map<IdentifierEntity, CTyEntityBaseDO> entityMap = CommonUtil.getEntityMap(identityList);
        List<CTyEntityBaseDO> entityBaseList = new ArrayList(entityMap.values());
        FlowPackageCheckedObject flowPackageCheckedObject = new FlowPackageCheckedObject();
        if (CollectionUtils.isEmpty(entityBaseList)) {
            return flowPackageCheckedObject;
        } else {
            List<FlowObject> disabledAddList = new CopyOnWriteArrayList();
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验权限 start");
            this.checkObjRight(baseObjectMap, entityMap, entityBaseList, disabledAddList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验权限 end");
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验是否被检出 start");
            this.checkObjLockStateInfo(baseObjectMap, entityMap, entityBaseList, disabledAddList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验是否被检出 end");
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验对象是否是最新大版本的最新小版本 start");
            this.checkObjMajorAndLatestVersion(baseObjectMap, entityMap, entityBaseList, disabledAddList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 校验对象是否是最新大版本的最新小版本 end");
            List<FlowObject> flowObjectList = new CopyOnWriteArrayList();
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 构建流程数据 start");
            this.buildFlowObject(entityBaseList, disabledAddList, flowObjectList);
            this.checkFlowObjectContainsWorkFlow(flowObjectList, disabledAddList, workflowId);
            flowPackageCheckedObject.setDisabledAddList(disabledAddList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 构建流程数据 end");
            if (CollUtil.isNotEmpty(flowObjectList)) {
                TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 设置基线编码展示信息 start");
                this.setBaseLineObject(flowObjectList);
                TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrow 设置基线编码展示信息 end");
            }

            flowPackageCheckedObject.setFlowObjectList(flowObjectList);
            return flowPackageCheckedObject;
        }
    }

    public FlowObjectStructuredReturnVO addCheckWorkFlowStartNoThrowCommon(FlowObjectStructuredParamVO flowObjectStructuredParamVO) {
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 方法入参flowObjectStructuredParamVO ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectStructuredParamVO)});
        ArgumentUtils.checkArgumentNull(flowObjectStructuredParamVO, "param");
        List<BaseObject> objList = flowObjectStructuredParamVO.getObjList();
        List<FlowObject> oirAllObjList = flowObjectStructuredParamVO.getOirAllObjList();
        BigInteger workflowId = flowObjectStructuredParamVO.getWorkFlowId();
        BigInteger workFlowContainerId = flowObjectStructuredParamVO.getWorkFlowContainerId();
        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        ArgumentUtils.checkArgumentEmpty(workflowId, "流程模板");
        FlowObjectStructuredReturnVO flowObjectStructuredReturnVO = new FlowObjectStructuredReturnVO();
        List<FlowObject> returnList = new ArrayList();
        List<FlowObject> returnRootList = new ArrayList();
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 流程包收集相关对象校验并构建流程对象 start");
        FlowPackageCheckedObject returnObj = this.addCheckWorkFlowStartNoThrow(objList, workflowId, workFlowContainerId);
        TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 流程包收集相关对象校验并构建流程对象 end");
        if (Objects.isNull(returnObj)) {
            return flowObjectStructuredReturnVO;
        } else {
            List<FlowObject> disabledAddList = returnObj.getDisabledAddList();
            flowObjectStructuredReturnVO.setDisabledAddList(disabledAddList);
            List<FlowObject> flowObjectList = returnObj.getFlowObjectList();
            if (flowObjectList == null) {
                flowObjectList = new ArrayList();
            }

            if (!CollectionUtils.isEmpty(disabledAddList)) {
                flowObjectList.removeAll(disabledAddList);
            }

            List<FlowObject> flowObjectCloneList = (List)flowObjectList.stream().collect(Collectors.toList());
            List<FlowObject> mpmObjectList = (List)flowObjectList.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
            if(oirAllObjList==null){
                oirAllObjList=new ArrayList<>();
            }
            List<FlowObject> oriMpmObjectList = (List)oirAllObjList.stream().filter((item) -> StringUtils.equals("ty.inteplm.mpm.CTyMPMProcessPlan", item.getRefObjectOtype()) || StringUtils.equals("ty.inteplm.mpm.CTyMPMOperation", item.getRefObjectOtype())).collect(Collectors.toList());
            flowObjectList.addAll(oirAllObjList);
            flowObjectList.removeAll(oriMpmObjectList);
            if (!CollectionUtils.isEmpty(mpmObjectList)) {
                TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 对工艺对象算根 start");
                this.tymMpmWorkFlowAdaptationService.batchSetMpmObjTypeMarkFlag(mpmObjectList);
                flowObjectList.removeAll(mpmObjectList);

                for(FlowObject flowObject : mpmObjectList) {
                    Integer typeMarkFlag = flowObject.getTypeMarkFlag();
                    typeMarkFlag = typeMarkFlag == null ? 0 : typeMarkFlag;
                    if (typeMarkFlag == 1) {
                        returnRootList.add(flowObject);
                    } else {
                        returnList.add(flowObject);
                    }
                }

                TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 对工艺对象算根 end");
            }

            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 零件算根 start");
            this.partCalcRootNode(flowObjectList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 零件算根 end");
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 处理flowObjectList start");
            this.handleIsRootData(flowObjectList, returnList, returnRootList);
            TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 处理flowObjectList end");
            returnList.removeAll(oirAllObjList);
            flowObjectStructuredReturnVO.setObjList(returnList);
            flowObjectStructuredReturnVO.setRootList(returnRootList);
            if (CollUtil.isNotEmpty(flowObjectStructuredParamVO.getColumns())) {
                List<FlowObject> objects = new ArrayList(returnList);
                objects.addAll(returnRootList);
                this.typlmCommonSearchService.dealFlowObjectDynamicColumns(flowObjectStructuredParamVO.getColumns(), objects);
            }

            if (Objects.isNull(workFlowContainerId)) {
                return flowObjectStructuredReturnVO;
            } else {
                if (CollectionUtils.isEmpty(disabledAddList) || Boolean.TRUE.equals(flowObjectStructuredParamVO.getSaveDataBase())) {
                    TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 对于流程容器id存在的数据做实时入库处理 start");
                    this.flowObjectIntoData(workFlowContainerId, flowObjectCloneList);
                    TyplmLoggerUtil.debug(log, () -> "addCheckWorkFlowStartNoThrowCommon 对于流程容器id存在的数据做实时入库处理 end");
                }

                return flowObjectStructuredReturnVO;
            }
        }
    }

    private void buildFlowObject(List<CTyEntityBaseDO> entityBaseList, List<FlowObject> disabledAddList, List<FlowObject> flowObjectList) {
        Set<BigInteger> typeSet = (Set)entityBaseList.stream().filter((entity) -> entity instanceof ITyTyped && !TyplmEntityBaseUtil.isEmptyOid(((ITyTyped)entity).getTypeoid())).map((entity) -> ((ITyTyped)entity).getTypeoid()).collect(Collectors.toSet());
        Map<BigInteger, TypeVueVO> typeMap;
        Map<BigInteger, TypeVueVO> rootParentTypeMap = new HashMap();
        if (!CollectionUtils.isEmpty(typeSet)) {
            List<TypeVueVO> typeVueVOS = this.typlmTypeService.queryTypeByIds(new ArrayList(typeSet));
            typeMap = (Map)typeVueVOS.stream().collect(Collectors.toMap(TypeDO::getOid, (e) -> e, (i, j) -> i));
            typeSet.clear();
            Map<BigInteger, Set<BigInteger>> typeParentOidMap = new HashMap();

            for(TypeVueVO type : typeVueVOS) {
                List<TypeDO> typeDOS = this.typlmTypeService.queryAllParentTypeByOid(type.getOid());
                Set<BigInteger> typeParentIds = (Set)typeDOS.stream().map(TypeDO::getOid).collect(Collectors.toSet());
                typeSet.addAll(typeParentIds);
                BigInteger oid = type.getOid();
                typeParentOidMap.put(oid, typeParentIds);
            }

            List<TypeVueVO> allParentTypeList = this.typlmTypeService.queryTypeByIds(new ArrayList(typeSet));
            Map<BigInteger, TypeVueVO> typeParentMap = (Map)allParentTypeList.stream().collect(Collectors.toMap(TypeDO::getOid, (e) -> e, (i, j) -> i));

            for(Map.Entry<BigInteger, Set<BigInteger>> entry : typeParentOidMap.entrySet()) {
                BigInteger key = (BigInteger)entry.getKey();

                for(BigInteger bigInteger : entry.getValue()) {
                    TypeVueVO typeVueVO = (TypeVueVO)typeParentMap.get(bigInteger);
                    if (typeVueVO != null && TyplmEntityBaseUtil.isEmptyOid(typeVueVO.getParentnodeoid())) {
                        rootParentTypeMap.put(key, typeVueVO);
                    }
                }
            }
        } else {
            typeMap = null;
        }

        Set<String> lifeCycleStateSet = (Set)entityBaseList.stream().filter((entity) -> entity instanceof ITyLifeCycleManaged && StringUtils.isNotBlank(((ITyLifeCycleManaged)entity).getLifecyclestagekey())).map((entity) -> ((ITyLifeCycleManaged)entity).getLifecyclestagekey()).collect(Collectors.toSet());
        Map<String, String> lifeCycleStateNameMap;
        if (!CollectionUtils.isEmpty(lifeCycleStateSet)) {
            lifeCycleStateNameMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(new ArrayList(lifeCycleStateSet), "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
        } else {
            lifeCycleStateNameMap = null;
        }

        Map<String, List<CTyEntityBaseDO>> entityBaseMap = (Map)entityBaseList.stream().collect(Collectors.groupingBy(CTyEntityBaseDO::getOtype));
        entityBaseMap.entrySet().stream().forEach((entryx) -> {
            String otype = (String)entryx.getKey();
            List<CTyEntityBaseDO> entityList = (List)entryx.getValue();
            Map<String, Boolean> stringBooleanMap = this.typlmFlowContainerObjectService.batchCheckEntityListInActiveFlowContainer(entityList, otype);
            Map<String, Object> requestContext = RequestContext.currentContext();
            Map<String, String> entityDisplayNameMap = CommonUtil.getEntityDisplayNameList(entityList);
            entityList.parallelStream().forEach((entity) -> {
                RequestContext.attachContext(requestContext);
                FlowObject flowObject = new FlowObject();
                flowObject.setEnableAdd(true);
                BigInteger refObjectOid = entity.getOid();
                String refObjectOtype = entity.getOtype();
                String refObjectName = (String)entityDisplayNameMap.get(entity.getIdentifierRef().toString());
                if (entity instanceof ITyLifeCycleManaged) {
                    ITyLifeCycleManaged obj = (ITyLifeCycleManaged)entity;
                    String lifecycleStageKey = obj.getLifecyclestagekey();
                    flowObject.setLifeCycleStageKey(lifecycleStageKey);
                    flowObject.setOriginalStatusKey(lifecycleStageKey);
                    flowObject.setOriginalStatusOid(obj.getLifecyclestageoid());
                    flowObject.setOriginalStatusOtype(obj.getLifecyclestageotype());
                    BigInteger lifecycleTemplateOid = obj.getLifecycletemplateoid();
                    flowObject.setLifecycleTemplateOid(lifecycleTemplateOid);
                    if (lifeCycleStateNameMap != null) {
                        flowObject.setCurrentStatusName((String)lifeCycleStateNameMap.get(lifecycleStageKey));
                    }
                }

                if (entity instanceof ITyTyped && !CollectionUtils.isEmpty(typeMap)) {
                    BigInteger typeoid = ((ITyTyped)entity).getTypeoid();
                    TypeVueVO type = (TypeVueVO)typeMap.get(typeoid);
                    if (type == null) {
                        return;
                    }

                    flowObject.setMasterId(type.getMasteredoid().toString());
                    flowObject.setType(type.getDisplayName());
                    flowObject.setTypeOid(typeoid);
                    TypeVueVO rootParentType = (TypeVueVO)rootParentTypeMap.get(typeoid);
                    if (rootParentType != null) {
                        flowObject.setCategory(rootParentType.getDisplayName());
                    }
                }

                refObjectName = this.setProcessObject(flowObject, entity, refObjectOtype, refObjectName);
                flowObject.setRefObjectOid(refObjectOid);
                flowObject.setRefObjectOtype(refObjectOtype);
                flowObject.setRefObjectName(refObjectName);
                if (Boolean.TRUE.equals(stringBooleanMap.get(refObjectOid.toString()))) {
                    flowObject.setEnableAdd(false);
                    flowObject.setDisabledAddReason("对所处流程未开启或正在流程中");
                }

                if (entity instanceof IteratorEntity) {
                    IteratorEntity obj = (IteratorEntity)entity;
                    Long latest = obj.getIslastiterated();
                    String lockStateInfo = obj.getLockstateinfo();
                    if (latest == null || latest == 0L) {
                        flowObject.setEnableAdd(false);
                        flowObject.setDisabledAddReason("不是最新版本不能启动流程");
                    }

                    if ("c/o".equals(lockStateInfo) || "wrk".equals(lockStateInfo)) {
                        flowObject.setEnableAdd(false);
                        flowObject.setDisabledAddReason("检出状态不能启动流程");
                    }

                    if (Boolean.TRUE.equals(flowObject.getEnableAdd())) {
                        flowObject.setBranchId(obj.getBranchid());
                        flowObject.setMasteredoid(obj.getMasteredoid());
                        this.typlmFlowObjectPackageLinkService.setFlowObjectIteratorInfo(flowObject, obj);
                    }
                }

                if (Boolean.TRUE.equals(flowObject.getEnableAdd())) {
                    flowObjectList.add(flowObject);
                } else {
                    disabledAddList.add(flowObject);
                }
            });
        });
        if (CollUtil.isNotEmpty(flowObjectList)) {
            this.setBaseLineObject(flowObjectList);
        }

    }

    private List<BaseObject> filterObjList(List<BaseObject> objList, BigInteger workFlowContainerId) {
        List<BaseObject> inProcessObjList = this.filterObjListInContainer(workFlowContainerId, (Map)null);
        if (!EntityBaseUtil.isEmptyOid(workFlowContainerId) && ObjectUtils.isNotEmpty(inProcessObjList)) {
            objList = (List)objList.stream().filter((item) -> inProcessObjList.stream().noneMatch((data) -> data.getOid().equals(item.getOid()) && data.getOtype().equals(item.getOtype()))).collect(Collectors.toList());
        }

        return objList;
    }

    private void checkObjMajorAndLatestVersion(Map<IdentifierEntity, BaseObject> baseObjectMap, Map<IdentifierEntity, CTyEntityBaseDO> entityMap, List<CTyEntityBaseDO> entityBaseList, List<FlowObject> disabledAddList) {
        Stream var10000 = entityBaseList.stream();
        ITyIterated.class.getClass();
        List<CTyEntityBaseDO> iteratedEntityList = (List)var10000.filter(ITyIterated.class::isInstance).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(iteratedEntityList)) {
            Map<BigInteger, ViewDefDO> viewDefMap = this.typlmCheckCollectionObjService.batchQueryViewMap(iteratedEntityList);
            Map<String, List<CTyEntityBaseDO>> iteratedEntityMap = (Map)iteratedEntityList.stream().collect(Collectors.groupingBy(CTyEntityBaseDO::getOtype));

            for(Map.Entry<String, List<CTyEntityBaseDO>> entry : iteratedEntityMap.entrySet()) {
                String otype = (String)entry.getKey();
                List<CTyEntityBaseDO> entityList = (List)entry.getValue();
                Map<BigInteger, List<CTyEntityBaseDO>> masterInfoMap = this.typlmCheckCollectionObjService.getMajorAndLatestVersionList(otype, entityList);
                List<CTyEntityBaseDO> currentUnLastedEntityList = this.typlmCheckCollectionObjService.getUnLastedEntityList(entityList, masterInfoMap, viewDefMap);
                if (!ObjectUtils.isEmpty(currentUnLastedEntityList)) {
                    this.buildUnLastedEntity(baseObjectMap, entityMap, entityBaseList, disabledAddList, currentUnLastedEntityList);
                }
            }
        }

    }

    private void buildUnLastedEntity(Map<IdentifierEntity, BaseObject> baseObjectMap, Map<IdentifierEntity, CTyEntityBaseDO> entityMap, List<CTyEntityBaseDO> entityBaseList, List<FlowObject> disabledAddList, List<CTyEntityBaseDO> currentUnLastedEntityList) {
        for(CTyEntityBaseDO cTyEntityBaseDO : currentUnLastedEntityList) {
            IdentifierEntity identifierEntity = new IdentifierEntity(cTyEntityBaseDO.getOid(), cTyEntityBaseDO.getOtype());
            this.buildDisabedFlowObjectList(identifierEntity, baseObjectMap, entityMap, entityBaseList, "对象不是最新大版本的最新小版本", disabledAddList);
        }

    }

    private void checkObjLockStateInfo(Map<IdentifierEntity, BaseObject> baseObjectMap, Map<IdentifierEntity, CTyEntityBaseDO> entityMap, List<CTyEntityBaseDO> entityBaseList, List<FlowObject> disabledAddList) {
        List<CTyEntityBaseDO> checkOutEntityList = (List)entityBaseList.stream().filter((item) -> item instanceof ITyLockable && StringUtils.isNotBlank(((ITyLockable)item).getLockstateinfo()) && ("c/o".equals(((ITyLockable)item).getLockstateinfo()) || "wrk".equals(((ITyLockable)item).getLockstateinfo()))).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(checkOutEntityList)) {
            Map<String, String> entityDisplayNameList = CommonUtil.getEntityDisplayNameList(checkOutEntityList);

            for(Map.Entry<String, String> stringStringEntry : entityDisplayNameList.entrySet()) {
                String key = (String)stringStringEntry.getKey();
                IdentifierEntity identifierEntity = new IdentifierEntity(key);
                this.buildDisabedFlowObjectList(identifierEntity, baseObjectMap, entityMap, entityBaseList, "对象被检出", disabledAddList);
            }
        }

    }

    private void checkObjRight(Map<IdentifierEntity, BaseObject> baseObjectMap, Map<IdentifierEntity, CTyEntityBaseDO> entityMap, List<CTyEntityBaseDO> entityBaseList, List<FlowObject> disabledAddList) {
        List<String> permissionList = (List)entityBaseList.stream().map((item) -> "读取").collect(Collectors.toList());
        List<AccessBatchDTO> accessBatchDTOS = this.typlmAccessJudgeService.checkAccessByObjectId(new ArrayList(entityBaseList), CommonUtil.getUser(), permissionList);
        if (!CollectionUtils.isEmpty(accessBatchDTOS)) {
            for(AccessBatchDTO accessBatchDTO : accessBatchDTOS) {
                if (!"Y".equalsIgnoreCase(accessBatchDTO.getIsAuthorized())) {
                    IdentifierEntity identifierEntity = new IdentifierEntity(new BigInteger(accessBatchDTO.getObjectoid()), accessBatchDTO.getObjectotype());
                    this.buildDisabedFlowObjectList(identifierEntity, baseObjectMap, entityMap, entityBaseList, "没有此对象的读取权限", disabledAddList);
                }
            }
        }

    }

    private void buildDisabedFlowObjectList(IdentifierEntity identifierEntity, Map<IdentifierEntity, BaseObject> baseObjectMap, Map<IdentifierEntity, CTyEntityBaseDO> entityMap, List<CTyEntityBaseDO> entityBaseList, String disabledAddReason, List<FlowObject> disabledAddList) {
        baseObjectMap.remove(identifierEntity);
        CTyEntityBaseDO remove = (CTyEntityBaseDO)entityMap.remove(identifierEntity);
        entityBaseList.remove(remove);
        String entityDisplayName = CommonUtil.getEntityDisplayName(remove);
        FlowObject flowObject = new FlowObject();
        flowObject.setRefObjectOid(identifierEntity.getOid());
        flowObject.setRefObjectOtype(identifierEntity.getOtype());
        flowObject.setRefObjectName(entityDisplayName);
        flowObject.setEnableAdd(false);
        flowObject.setDisabledAddReason(disabledAddReason);
        disabledAddList.add(flowObject);
    }

    private void addRelationObj(List<BaseObject> objList, List<BaseObject> newObjList) {
        TyplmLoggerUtil.debug(log, () -> "addRelationObj 方法入参objList ==> 【{}】; newObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(newObjList)});
        List<String> list = Arrays.asList(this.typeNames.split(","));
        Map<String, List<BaseObject>> objMap = (Map)objList.stream().collect(Collectors.groupingBy(IdentifierEntity::getOtype));
        objMap.entrySet().stream().forEach((entry) -> {
            String otype = (String)entry.getKey();
            List<BaseObject> baseObjectList = (List)entry.getValue();
            newObjList.addAll(baseObjectList);
            if (HANDLE_OTYPES.contains(otype)) {
                List<String> oidList = (List)((List<BaseObject>)entry.getValue()).stream().map((baseObject) -> baseObject.getOid().toString()).collect(Collectors.toList());
                List<CTyEntityBaseDO> entityList = CommonUtil.getEntitys(otype, oidList);
                Map<String, Object> requestContext = RequestContext.currentContext();
                entityList.parallelStream().forEach((item) -> {
                    RequestContext.attachContext(requestContext);
                    if (item instanceof ITyTyped) {
                        BigInteger typeOid = ((ITyTyped)item).getTypeoid();
                        TypeDO typeDO = this.typlmTypeService.queryTypeByOID(typeOid);
                        if (typeDO != null) {
                            List<BigInteger> typeMasterOidList = new ArrayList();
                            typeMasterOidList.add(typeDO.getMasteredoid());
                            List<TypeMasterDO> typeMasterDOList = this.typlmTypeMasterService.queryTypeMasterByOIDS(typeMasterOidList);
                            if (!CollUtil.isEmpty(typeMasterDOList)) {
                                String displayName = ((TypeMasterDO)typeMasterDOList.get(0)).getDisplayname();
                                if (list.contains(displayName)) {
                                    BigInteger itemOid = item.getOid();
                                    if ("ty.inteplm.part.CTyPart".equals(otype)) {
                                        this.addRelationDoc(itemOid.toString(), newObjList, false);
                                    } else {
                                        List<PartDetailsVO> partDetailsVOS = this.typlmDocumentService.queryDocDescribeLinkPartByDoc(itemOid, otype);
                                        if (ObjectUtils.isNotEmpty(partDetailsVOS)) {
                                            for(PartDetailsVO partDetailsVO : partDetailsVOS) {
                                                BaseObject part = new BaseObject();
                                                part.setOid(new BigInteger(partDetailsVO.getOid()));
                                                part.setOtype(partDetailsVO.getOtype());
                                                newObjList.add(part);
                                            }
                                        }
                                    }

                                }
                            }
                        }
                    }
                });
            }
        });
    }

    public void insertWithNotObjList(WorkFlowObjectPackage workFlowObjectPackage, List<BigInteger> firstUserIdList) {
        TyplmLoggerUtil.debug(log, () -> "insertWithNotObjList 方法入参workFlowObjectPackage ==> 【{}】; firstUserIdList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage), JSONObject.toJSONString(firstUserIdList)});
        ArgumentUtils.checkArgumentEmpty(workFlowObjectPackage, "流程");
        FlowObjectPackage flowObjectPackage = new FlowObjectPackage();
        this.typlmFlowObjectPackageService.insert(flowObjectPackage);
        BigInteger flowObjectPackageOid = flowObjectPackage.getOid();
        String flowObjectPackageOtype = flowObjectPackage.getOtype();
        workFlowObjectPackage.setBaseObjectOid(flowObjectPackageOid);
        workFlowObjectPackage.setBaseObjectOtype(flowObjectPackageOtype);
        this.buildUserTaskList(workFlowObjectPackage, firstUserIdList);
        this.typlmWorkFlowCommonViewService.insert(workFlowObjectPackage);
    }

    private void buildUserTaskList(WorkFlowContainerView workFlowContainerView, List<BigInteger> firstUserIdList) {
        TyplmLoggerUtil.debug(log, () -> "buildUserTaskList 方法入参workFlowContainerView ==> 【{}】; firstUserIdList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerView), JSONObject.toJSONString(firstUserIdList)});
        if (workFlowContainerView == null) {
            throw SystemErrorCodeEnum.WORK_FLOW_NO_START_EVENT.getException(new Object[0]);
        } else {
            ArgumentUtils.checkArgumentEmpty(firstUserIdList, "firstUserIdList");
            List<String> firstUserIdStrList = (List)firstUserIdList.stream().map(BigInteger::toString).collect(Collectors.toList());
            List<PdmUserDTO> pdmUserDTOS = this.pdmUserService.getUserListByIds(firstUserIdList);
            if (CollUtil.isEmpty(pdmUserDTOS)) {
                throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{"用户信息不存在！"});
            } else {
                List<UserTaskDTO> userTaskDTOList = workFlowContainerView.getUserTaskList();
                if (userTaskDTOList == null) {
                    userTaskDTOList = new ArrayList();
                }

                Map<String, UserTaskDTO> userTaskMap = (Map)userTaskDTOList.stream().collect(Collectors.toMap(UserTaskDTO::getId, (userTaskDTO) -> userTaskDTO));
                String deploymentId = workFlowContainerView.getDeploymentId();

                for(UserTask userTask : this.typlmFlowElementService.getStartUserTask(deploymentId)) {
                    String taskId = userTask.getId();
                    UserTaskDTO viewUserTask = (UserTaskDTO)userTaskMap.get(taskId);
                    List<PdmUserDTO> taskHandlerList = this.typlmFlowHandlerService.getTaskHandler(userTask, workFlowContainerView.getOid());
                    if (CollUtil.isEmpty(taskHandlerList)) {
                        throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{"参与者列表为空！请维护流程模板"});
                    }

                    List<String> taskHandlerOidList = (List)taskHandlerList.stream().map(PdmUserDTO::getOid).collect(Collectors.toList());
                    if (!CollUtil.containsAll(taskHandlerOidList, firstUserIdStrList)) {
                        throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{"当前选择的用户不在参与者列表中！"});
                    }

                    viewUserTask.setUserList(pdmUserDTOS);
                }

                workFlowContainerView.setUserTaskList(userTaskDTOList);
            }
        }
    }

    public void insert(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "insert 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        ArgumentUtils.checkArgumentEmpty(workFlowObjectPackage, "流程");
        List<FlowObject> objList = workFlowObjectPackage.getFlowObjectList();
        if (CollectionUtils.isEmpty(objList)) {
            throw SystemErrorCodeEnum.WORK_FLOW_OBJECT_LIST_CAN_NOT_EMPTY.getException(new Object[0]);
        } else {
            TyplmLoggerUtil.debug(log, () -> "insert 先做一下去重，同一份支只能有一个版本对象避免重复 start");
            objList = this.distinctObjListAndCheckObjInActiveFlow(objList);
            TyplmLoggerUtil.debug(log, () -> "insert 先做一下去重，同一份支只能有一个版本对象避免重复 end");
            TyplmLoggerUtil.debug(log, () -> "insert 为流程容器新增对象包 start");
            FlowObjectPackage flowObjectPackage = new FlowObjectPackage();
            this.typlmFlowObjectPackageService.insert(flowObjectPackage);
            TyplmLoggerUtil.debug(log, () -> "insert 为流程容器新增对象包 end");
            BigInteger flowObjectPackageOid = flowObjectPackage.getOid();
            String flowObjectPackageOtype = flowObjectPackage.getOtype();
            workFlowObjectPackage.setBaseObjectOid(flowObjectPackageOid);
            workFlowObjectPackage.setBaseObjectOtype(flowObjectPackageOtype);
            workFlowObjectPackage.setCode(workFlowObjectPackage.getCodeNumber());
            TyplmLoggerUtil.debug(log, () -> "insert 任务分配中将分配的工艺对象子级分配属性与根一级同步 start");
            this.tymMpmWorkFlowAdaptationService.setAssignmentsMpmChildData(objList);
            TyplmLoggerUtil.debug(log, () -> "insert 任务分配中将分配的工艺对象子级分配属性与根一级同步 end");
            TyplmLoggerUtil.debug(log, () -> "insert 遍历流程对象 start");

            try (SqlSession sqlSession = this.sqlSessionFactory.openSession(ExecutorType.BATCH)) {
                TyplmFlowObjectPackageLinkMapper mapper = (TyplmFlowObjectPackageLinkMapper)sqlSession.getMapper(TyplmFlowObjectPackageLinkMapper.class);

                for(FlowObject flowObject : objList) {
                    flowObject.setPackageOid(flowObjectPackageOid);
                    flowObject.setPackageOtype(flowObjectPackageOtype);
                    this.buildFlowObjectPackageLink(flowObject);
                    TyplmLoggerUtil.debug(log, () -> "insert 创建FlowObjectPackageLink start");
                    mapper.insert(flowObject);
                    TyplmLoggerUtil.debug(log, () -> "insert 创建FlowObjectPackageLink end");
                }

                sqlSession.commit();
            }

            TyplmLoggerUtil.debug(log, () -> "insert 遍历流程对象 end");
            TyplmLoggerUtil.debug(log, () -> "insert 新建通用流程视图 start");
            this.typlmWorkFlowCommonViewService.insert(workFlowObjectPackage);
            TyplmLoggerUtil.debug(log, () -> "insert 新建通用流程视图 end");
            TyplmLoggerUtil.debug(log, () -> "insert 将对象和流程包加入到流程中RuFlowObject start");
            this.insertContainerSaveFlowObjectStatus(workFlowObjectPackage);
            TyplmLoggerUtil.debug(log, () -> "insert 将对象和流程包加入到流程中RuFlowObject end");
        }
    }

    private Map<String, Boolean> batchCheckObjInActiveFlowContainer(List<FlowObject> dbObjList) {
        TyplmLoggerUtil.debug(log, () -> "insert 批量校验对象是否在流程中 start");
        Map<String, Boolean> checkResult = new HashMap();
        ((Map)dbObjList.stream().collect(Collectors.groupingBy(FlowObjectPackageLink::getRefObjectOtype))).forEach((otype, flowObjectList) -> {
            FlowObject firstObj = (FlowObject)((List<FlowObject> )flowObjectList).get(0);
            boolean isIterable = !firstObj.getRefObjectOid().equals(firstObj.getBranchId());
            List<RuFlowObject> ruFlowObject;
            if (isIterable) {
                List<BigInteger> branchidList = ((List<FlowObject>)flowObjectList).stream().map(FlowObjectPackageLink::getBranchId).collect(Collectors.toList());
                ruFlowObject = this.typlmRuFlowObjectService.batchGetRuFlowObjectByBranchidList((String) otype, branchidList);
            } else {
                List<BigInteger> idList = ((List<FlowObject>)flowObjectList).stream().map(FlowObjectPackageLink::getRefObjectOid).collect(Collectors.toList());
                ruFlowObject = this.typlmRuFlowObjectService.batchGetRuFlowObjectByIdList(idList, (String) otype);
            }

            if (!CollectionUtils.isEmpty(ruFlowObject)) {
                for(RuFlowObject flowObject : ruFlowObject) {
                    if (flowObject.getFlowstatus() < WorkFlowContainerStatusEnum.COMPLETED.getValue()) {
                        checkResult.put(flowObject.getObjoid().toString(), true);
                    }
                }
            }

        });
        TyplmLoggerUtil.debug(log, () -> "insert 批量校验对象是否在流程中 end");
        return checkResult;
    }

    private void buildFlowObjectPackageLink(FlowObject flowObject) {
        flowObject.setOid(this.snowflakeIdComponent.getInstance().nextId());
        flowObject.setUpdateMarkFlag(0);
        if (flowObject.getTypeMarkFlag() == null) {
            flowObject.setTypeMarkFlag(1);
        }

        Date now = new Date();
        flowObject.setCreateTime(now);
        flowObject.setUpdateTime(now);
        flowObject.setUpdateCount(0L);
        flowObject.setMarkForDelete(0L);
    }

    private static List<FlowObject> getDbObjList(List<FlowObject> objList) {
        List<FlowObject> dbObjList = new CopyOnWriteArrayList();
        Map<String, List<FlowObject>> objMap = (Map)objList.stream().collect(Collectors.groupingBy(FlowObjectPackageLink::getRefObjectOtype));
        objMap.forEach((otype, value) -> {
            List<String> oidList = (List)value.stream().map((flowObject) -> flowObject.getRefObjectOid().toString()).collect(Collectors.toList());
            List<CTyEntityBaseDO> entityList = CommonUtil.getEntitys(otype, oidList);
            entityList.parallelStream().forEach((entity) -> {
                FlowObject flowObject = new FlowObject();
                flowObject.setRefObjectOid(entity.getOid());
                flowObject.setRefObjectOtype(entity.getOtype());
                if (entity instanceof ITyIterated) {
                    flowObject.setBranchId(((ITyIterated)entity).getBranchid());
                } else {
                    flowObject.setBranchId(entity.getOid());
                }

                dbObjList.add(flowObject);
            });
        });
        return (List)dbObjList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet(Comparator.comparing(FlowObjectPackageLink::getBranchId))), ArrayList::new));
    }

    private List<FlowObject> distinctObjListAndCheckObjInActiveFlow(List<FlowObject> objList) {
        List<FlowObject> dbObjList = getDbObjList(objList);
        Map<String, Boolean> checkResult = this.batchCheckObjInActiveFlowContainer(dbObjList);
        return (List)objList.stream().filter((item) -> dbObjList.stream().anyMatch((data) -> {
            if (data.getRefObjectOid().equals(item.getRefObjectOid()) && data.getRefObjectOtype().equals(item.getRefObjectOtype())) {
                if (Boolean.TRUE.equals(checkResult.get(data.getRefObjectOid().toString()))) {
                    throw SystemErrorCodeEnum.OBJECT_IS_IN_A_PROCESS.getException(new Object[]{item.getRefObjectName()});
                } else {
                    return true;
                }
            } else {
                return false;
            }
        })).collect(Collectors.toList());
    }

    private List<FlowObject> distinctObjList(List<FlowObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "distinctObjList 方法入参objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        if (CollUtil.isEmpty(objList)) {
            return Lists.emptyList();
        } else {
            List<FlowObject> dbObjList = getDbObjList(objList);
            return (List)objList.stream().filter((item) -> dbObjList.stream().anyMatch((data) -> data.getRefObjectOid().equals(item.getRefObjectOid()) && data.getRefObjectOtype().equals(item.getRefObjectOtype()))).collect(Collectors.toList());
        }
    }

    public void update(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "update 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        boolean checkFlowObjectList = this.checkFlowObjectList(workFlowObjectPackage);
        if (!checkFlowObjectList) {
            this.typlmWorkFlowCommonViewService.update(workFlowObjectPackage);
        } else {
            List<FlowObject> objList = workFlowObjectPackage.getFlowObjectList();
            if (CollectionUtils.isEmpty(objList)) {
                throw SystemErrorCodeEnum.WORK_FLOW_OBJECT_LIST_CAN_NOT_EMPTY.getException(new Object[0]);
            } else {
                objList = this.distinctObjList(objList);
                this.updateObjectLink(workFlowObjectPackage, objList);
                this.typlmWorkFlowCommonViewService.update(workFlowObjectPackage);
                this.updateContainerSaveFlowObjectStatus(workFlowObjectPackage);
            }
        }
    }

    private boolean checkFlowObjectList(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "checkFlowObjectList 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        String baseObjectOtype = workFlowObjectPackage.getBaseObjectOtype();
        return !"ty.inteplm.change.CTyChangeIssue".equals(baseObjectOtype);
    }

    public void updateObjectLink(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "updateObjectLink 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        List<FlowObject> objList = workFlowObjectPackage.getFlowObjectList();
        if (CollectionUtils.isEmpty(objList)) {
            throw SystemErrorCodeEnum.WORK_FLOW_OBJECT_LIST_CAN_NOT_EMPTY.getException(new Object[0]);
        } else {
            this.updateObjectLink(workFlowObjectPackage, objList, false);
        }
    }

    public void getEmptyWorkFlowObjectPackage(WorkFlowObjectPackage workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 方法入参workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
        ArgumentUtils.checkArgumentEmpty(workFlowContainer, "参数");
        ArgumentUtils.checkArgumentEmpty(workFlowContainer.getWorkFlowId(), "流程模板");
        BigInteger containerOid = workFlowContainer.getContainerOid();
        String containerOtype = workFlowContainer.getContainerOtype();
        if (containerOid == null || BigInteger.ZERO.equals(containerOid) || StringUtils.isBlank(containerOtype)) {
            Product defaultProduct = this.productService.getDefaultProduct();
            if (defaultProduct == null) {
                throw SystemErrorCodeEnum.MUST_CHOOSE_CONTAINER_OR_HAVE_DEFAULT_PRODUCT.getException(new Object[0]);
            }

            workFlowContainer.setContainerOid(new BigInteger(defaultProduct.getOid()));
            workFlowContainer.setContainerOtype(defaultProduct.getOtype());
        }

        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 生成新流程容器 start");
        this.typlmWorkFlowContainerService.buildWorkFlowContainer(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 生成新流程容器 end");
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 生成空流程视图 start");
        this.typlmWorkFlowContainerViewService.buildWorkContainerView(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 生成空流程视图 end");
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 从redis获取对应流程节点的处理人 start");
        this.typlmFlowCommonService.buildRecentFlowUsers(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 从redis获取对应流程节点的处理人 end");
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 从redis获取对应流程模板的管理者和监控者信息 start");
        this.typlmFlowCommonService.buildRecentFlowManageAndSupervisor(workFlowContainer);
        TyplmLoggerUtil.debug(log, () -> "getEmptyWorkFlowObjectPackage 从redis获取对应流程模板的管理者和监控者信息 end");
        workFlowContainer.setTargetStatusNeed(this.targetStatusNeed);
    }

    public Boolean objectListCheckWorkFlowStartRules(List<BaseObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "objectListCheckWorkFlowStartRules 方法入参objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        ArgumentUtils.checkArgumentEmpty(objList, "所选对象");
        this.checkObjListEnableStart(objList, (BigInteger)null, (String)null);
        return true;
    }

    public void delete(WorkFlowContainer workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "delete 方法入参workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
        BigInteger packageOid = workFlowContainer.getBaseObjectOid();
        String baseObjectOtype = workFlowContainer.getBaseObjectOtype();
        this.typlmFlowObjectPackageService.delete(packageOid);
        Map<String, Object> params = new HashMap(8);
        params.put("packageOid", packageOid);
        params.put("packageOtype", baseObjectOtype);
        this.typlmFlowObjectPackageLinkService.delete(params);
    }

    public void delete(Collection<WorkFlowContainer> workFlowContainers) {
        TyplmLoggerUtil.debug(log, () -> "delete 方法入参workFlowContainers ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainers)});
        Set<BigInteger> packageSet = (Set)workFlowContainers.stream().map(WorkFlowContainer::getBaseObjectOid).collect(Collectors.toSet());
        this.typlmFlowObjectPackageService.delete(packageSet);
        this.typlmFlowObjectPackageLinkService.deleteByPackages(packageSet);
    }

    public void checkEnableNext(FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "checkEnableNext 方法入参flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowTaskInfo)});
        List<String> errorMessageList = new ArrayList();
        this.checkStatus(errorMessageList, flowTaskInfo);
        if (!errorMessageList.isEmpty()) {
            String errorMessage = String.join(";", errorMessageList);
            throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{errorMessage});
        }
    }

    public String getType() {
        return "com.ty.entity.workFlow.FlowObjectPackage";
    }

    public Class<? extends TyplmWorkFlowContainerInstanceService> getInstanceClass() {
        return this.getClass();
    }

    public Class<? extends WorkFlowContainerView> getContainerViewSubClass() {
        return WorkFlowObjectPackage.class;
    }

    public WorkFlowContainerView getContainerDetail(WorkFlowContainerView workFlowContainerView) {
        TyplmLoggerUtil.debug(log, () -> "getContainerDetail 方法入参workFlowContainerView ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerView)});
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)BeanUtil.toBean(workFlowContainerView, WorkFlowObjectPackage.class);
        BigInteger baseObjectOid = workFlowContainerView.getBaseObjectOid();
        String baseObjectOtype = workFlowContainerView.getBaseObjectOtype();
        List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(baseObjectOid, baseObjectOtype);
        if (CollUtil.isNotEmpty(flowObjectList)) {
            this.setBaseLineObject(flowObjectList);
        }

        workFlowObjectPackage.setFlowObjectList(flowObjectList);
        workFlowObjectPackage.setTargetStatusNeed(this.targetStatusNeed);
        return workFlowObjectPackage;
    }

    public WorkFlowContainerView getContainerDetail(WorkFlowContainerView workFlowContainerView, FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "getContainerDetail 方法入参workFlowContainerView ==> 【{}】; flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerView), JSONObject.toJSONString(flowTaskInfo)});
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)BeanUtil.toBean(workFlowContainerView, WorkFlowObjectPackage.class);
        BigInteger baseObjectOid = workFlowContainerView.getBaseObjectOid();
        String baseObjectOtype = workFlowContainerView.getBaseObjectOtype();
        List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(baseObjectOid, baseObjectOtype);
        flowObjectList = this.filterFlowObjectList(flowObjectList, flowTaskInfo);
        if (CollUtil.isNotEmpty(flowObjectList)) {
            this.setBaseLineObject(flowObjectList);
        }

        workFlowObjectPackage.setFlowObjectList(flowObjectList);
        this.errorMarkService.resetErrorMarkInfoByWorkFlow(flowTaskInfo, flowObjectList);
        flowObjectList = (List)flowObjectList.stream().sorted(Comparator.comparing(FlowObjectPackageLink::getOid)).collect(Collectors.toList());
        workFlowObjectPackage.setFlowObjectList(flowObjectList);
        workFlowObjectPackage.setTargetStatusNeed(this.targetStatusNeed);
        return workFlowObjectPackage;
    }

    public List<FlowObject> getAppFlowObjectList(WorkFlowContainerView workFlowContainerView) {
        TyplmLoggerUtil.debug(log, () -> "getAppFlowObjectList 方法入参workFlowContainerView ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerView)});
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)BeanUtil.toBean(workFlowContainerView, WorkFlowObjectPackage.class);
        return workFlowObjectPackage.getFlowObjectList();
    }

    public void handlePartRoot(List<FlowObject> flowObjectList) {
        TyplmLoggerUtil.debug(log, () -> "handlePartRoot 方法入参flowObjectList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList)});
        if (!CollectionUtils.isEmpty(flowObjectList)) {
            List<FlowObject> partObjList = (List)flowObjectList.stream().filter((item) -> StringUtils.equals("ty.inteplm.part.CTyPart", item.getRefObjectOtype())).collect(Collectors.toList());
            List<BigInteger> partList = (List)partObjList.stream().map(FlowObjectPackageLink::getRefObjectOid).distinct().collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(partList)) {
                CalculatePartRootDTO calculatePartRootDTO = new CalculatePartRootDTO();
                calculatePartRootDTO.setNowPartList(partList);
                List<BigInteger> bigIntegers = this.typlmPartBomFlowObjectService.batchCalculatePartRootNode(calculatePartRootDTO);
                if (!CollectionUtils.isEmpty(bigIntegers)) {
                    for(FlowObject flowObject : partObjList) {
                        flowObject.setObjHasFlowStatus(ObjectHasFlowedEnum.IN_THIS_PROCESS.getCode());
                        if (bigIntegers.contains(flowObject.getRefObjectOid())) {
                            flowObject.setTypeMarkFlag(1);
                        } else {
                            flowObject.setTypeMarkFlag(0);
                        }
                    }

                }
            }
        }
    }

    public void checkEnableStart(WorkFlowContainerView workFlowContainerView, BigInteger objectOid, String objectOtype) {
        TyplmLoggerUtil.debug(log, () -> "checkEnableStart 方法入参objectOid ==> 【{}】; objectOtype ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objectOid), objectOtype});
        List<String> errorMessageList = new ArrayList();
        this.checkStatus(objectOid, objectOtype, errorMessageList);
        if (!errorMessageList.isEmpty()) {
            String errorMessage = String.join(";", errorMessageList);
            throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{errorMessage});
        }
    }

    public void handleFlowProcessEnd(WorkFlowContainer workFlowContainer) {
        this.updateState(workFlowContainer);
    }

    public void updateByFlowTaskInfo(FlowTaskInfo flowTaskInfo, List<MultipartFile> fileList) {
        JSONObject viewObject = flowTaskInfo.getViewObject();
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)viewObject.toJavaObject(WorkFlowObjectPackage.class);
        this.updateObjectLinkDistributeObjectsByFlowTaskInfo(flowTaskInfo);
        this.typlmWorkFlowCommonViewService.update(workFlowObjectPackage);
    }

    private Task getNonTask(String taskId) {
        TyplmLoggerUtil.debug(log, () -> "getNonTask 方法入参taskId ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(taskId)});
        if (StringUtils.isBlank(taskId)) {
            throw SystemErrorCodeEnum.TASK_ID_NO_EXIST.getException(new Object[0]);
        } else {
            Task task = (Task)((TaskQuery)this.taskService.createTaskQuery().taskId(taskId)).singleResult();
            if (task == null) {
                throw SystemErrorCodeEnum.TASK_NO_EXIST.getException(new Object[0]);
            } else {
                return task;
            }
        }
    }

    public void updateObjectLinkByFlowTaskInfo(FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "updateObjectLinkByFlowTaskInfo 方法入参flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowTaskInfo)});
        JSONObject viewObject = flowTaskInfo.getViewObject();
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)viewObject.toJavaObject(WorkFlowObjectPackage.class);
        this.updateObjectLink(workFlowObjectPackage);
    }

    public void updateObjectLinkDistributeObjectsByFlowTaskInfo(FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "updateObjectLinkDistributeObjectsByFlowTaskInfo 方法入参flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowTaskInfo)});
        JSONObject viewObject = flowTaskInfo.getViewObject();
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)viewObject.toJavaObject(WorkFlowObjectPackage.class);
        List<FlowObject> objList = workFlowObjectPackage.getFlowObjectList();
        if (!CollectionUtils.isEmpty(objList)) {
            this.tymMpmWorkFlowAdaptationService.setAssignmentsMpmChildData(objList);
            List<FlowObjectPackageLink> listByPackage = this.typlmFlowObjectPackageLinkService.getListByPackage(workFlowObjectPackage.getBaseObjectOid(), workFlowObjectPackage.getBaseObjectOtype());
            Map<BigInteger, FlowObjectPackageLink> flowObjMap = (Map)listByPackage.stream().collect(Collectors.toMap(FlowObjectPackageLink::getOid, (flowObjectPackageLink) -> flowObjectPackageLink));

            for(FlowObject flowObject : objList) {
                BigInteger oid = flowObject.getOid();
                FlowObject updateObj = new FlowObject();
                updateObj.setOid(oid);
                updateObj.setTaskdefkey(flowObject.getTaskdefkey());
                updateObj.setTaskname(flowObject.getTaskname());
                if (oid != null && BigInteger.ZERO.compareTo(oid) != 0 && flowObjMap.containsKey(oid)) {
                    this.typlmFlowObjectPackageLinkService.updateSelective(updateObj);
                }

                flowObjMap.remove(oid);
            }

        }
    }

    public void updateObjectLinkDistributeObjects(WorkFlowObjectPackage workFlowObjectPackage) {
        List<FlowObject> objList = workFlowObjectPackage.getFlowObjectList();
        if (!CollectionUtils.isEmpty(objList)) {
            this.tymMpmWorkFlowAdaptationService.setAssignmentsMpmChildData(objList);
            List<FlowObjectPackageLink> listByPackage = this.typlmFlowObjectPackageLinkService.getListByPackage(workFlowObjectPackage.getBaseObjectOid(), workFlowObjectPackage.getBaseObjectOtype());
            Map<BigInteger, FlowObjectPackageLink> flowObjMap = (Map)listByPackage.stream().collect(Collectors.toMap(FlowObjectPackageLink::getOid, (flowObjectPackageLink) -> flowObjectPackageLink));

            try (SqlSession sqlSession = this.sqlSessionFactory.openSession(ExecutorType.BATCH)) {
                TyplmFlowObjectPackageLinkMapper mapper = (TyplmFlowObjectPackageLinkMapper)sqlSession.getMapper(TyplmFlowObjectPackageLinkMapper.class);

                for(FlowObject flowObject : objList) {
                    BigInteger oid = flowObject.getOid();
                    if (oid != null && BigInteger.ZERO.compareTo(oid) != 0 && flowObjMap.containsKey(oid)) {
                        mapper.updateByPrimaryKey(flowObject);
                    }
                }
            }

        }
    }

    public void handleNeedDistributeObject(UserTask userTask, FlowTaskInfo flowTaskInfo) {
    }

    public boolean checkNeedDistributeObject(UserTask userTask, FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "checkNeedDistributeObject 方法入参userTask ==> 【{}】; flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(userTask), JSONObject.toJSONString(flowTaskInfo)});
        JSONObject viewObject = flowTaskInfo.getViewObject();
        if (ObjectUtils.isEmpty(viewObject)) {
            return true;
        } else {
            WorkFlowObjectPackage workFlowContainerView = (WorkFlowObjectPackage)viewObject.toJavaObject(WorkFlowObjectPackage.class);
            List<FlowObject> flowObjectList = workFlowContainerView.getFlowObjectList();
            return this.typlmFlowObjectTaskLinkService.hasDistributeObjects(userTask, flowObjectList);
        }
    }

    private void insertContainerSaveFlowObjectStatus(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "insertContainerSaveFlowObjectStatus 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
        this.checkRuFlowObjectUnique(flowObjectList);
        List<RuFlowObject> ruFlowObjectList = new ArrayList();

        for(FlowObject flowObject : flowObjectList) {
            RuFlowObject ruFlowObject = this.getRuFlowObject(flowObject);
            ruFlowObject.setFlowcontaineroid(workFlowObjectPackage.getOid());
            ruFlowObject.setFlowcontainerotype(workFlowObjectPackage.getOtype());
            ruFlowObject.setFlowstatus(workFlowObjectPackage.getStatus());
            ruFlowObject.setOid(this.snowflakeIdComponent.getInstance().nextId());
            TyplmEntityBaseUtil.fillCommonFieldForCreate(ruFlowObject);
            ruFlowObjectList.add(ruFlowObject);
        }

        this.typlmEntityBaseService.batchInsertWithCommit(ruFlowObjectList);
    }

    private void checkRuFlowObjectUnique(List<FlowObject> flowObjectList) {
        List<BigInteger> objOidList = new ArrayList();
        List<BigInteger> branchIdList = new ArrayList();

        for(FlowObject flowObject : flowObjectList) {
            BigInteger objectOid = flowObject.getRefObjectOid();
            BigInteger branchId = flowObject.getBranchId();
            if (!TyplmEntityBaseUtil.isEmptyOid(objectOid)) {
                objOidList.add(objectOid);
            }

            if (!TyplmEntityBaseUtil.isEmptyOid(branchId)) {
                branchIdList.add(branchId);
            }
        }

        this.checkObjoidAndBranchidUnique(objOidList, branchIdList);
    }

    public void checkObjoidAndBranchidUnique(List<BigInteger> objoidList, List<BigInteger> branchidList) {
        if (!CollUtil.isEmpty(objoidList) || !CollUtil.isEmpty(branchidList)) {
            List<CTyEntityBaseDO> exitObjOidList = new ArrayList();

            for(List<BigInteger> subList : CollUtil.split(objoidList, 800)) {
                exitObjOidList.addAll(this.typlmFlowObjectPackageCheckMapper.batchCheckObjidUnique(subList));
            }

            List<CTyEntityBaseDO> exitBranchIdList = new ArrayList();

            for(List<BigInteger> subList : CollUtil.split(branchidList, 800)) {
                exitBranchIdList.addAll(this.typlmFlowObjectPackageCheckMapper.batchCheckBranchidUnique(subList));
            }

            if (CollUtil.isNotEmpty(exitBranchIdList)) {
                String displayName = CommonUtil.getEntityDisplayName(exitBranchIdList);
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_IN_WORKFLOW, new String[]{displayName});
            }

            if (CollUtil.isNotEmpty(exitObjOidList)) {
                String displayName = CommonUtil.getEntityDisplayName(exitObjOidList);
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_IN_WORKFLOW, new String[]{displayName});
            }

        }
    }

    private RuFlowObject getRuFlowObject(FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "getRuFlowObject 方法入参flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject)});
        RuFlowObject ruFlowObject = new RuFlowObject();
        ruFlowObject.setObjoid(flowObject.getRefObjectOid());
        String otype = flowObject.getRefObjectOtype();
        ruFlowObject.setObjotype(otype);
        ruFlowObject.setBranchid(flowObject.getBranchId());
        BigInteger masteredoid = flowObject.getMasteredoid();
        if (!EntityBaseUtil.isEmptyOid(masteredoid)) {
            ruFlowObject.setMasteredoid(masteredoid);
            ruFlowObject.setMasteredotype(TyEntityMapperUtil.getMasteredOtype(otype));
        }

        return ruFlowObject;
    }

    private void updateContainerSaveFlowObjectStatus(WorkFlowObjectPackage workFlowObjectPackage) {
        TyplmLoggerUtil.debug(log, () -> "updateContainerSaveFlowObjectStatus 方法入参workFlowObjectPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowObjectPackage)});
        List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
        Map<String, Object> params = new HashMap();
        WorkFlowContainer rootWorkFlowContainer = this.findRootWorkFlowContainer(workFlowObjectPackage);
        params.put("flowcontaineroid", rootWorkFlowContainer.getOid());
        params.put("flowcontainerotype", workFlowObjectPackage.getOtype());
        List<RuFlowObject> ruFlowObjectList = this.typlmRuFlowObjectService.simpleQueryListByParams(params);

        for(FlowObject flowObject : flowObjectList) {
            boolean flag = false;

            for(RuFlowObject ruFlowObject : ruFlowObjectList) {
                if (flowObject.getRefObjectOid().equals(ruFlowObject.getObjoid()) && flowObject.getRefObjectOtype().equals(ruFlowObject.getObjotype())) {
                    ruFlowObjectList.remove(ruFlowObject);
                    flag = true;
                    break;
                }
            }

            if (!flag) {
                RuFlowObject ruFlowObject = this.getRuFlowObject(flowObject);
                this.typlmFlowContainerObjectService.insertRuFlowObject(rootWorkFlowContainer, ruFlowObject);
            }
        }

        Set<BigInteger> oidSet = new HashSet();

        for(RuFlowObject ruFlowObject : ruFlowObjectList) {
            if (!workFlowObjectPackage.getBaseObjectOid().equals(ruFlowObject.getObjoid()) || !workFlowObjectPackage.getBaseObjectOtype().equals(ruFlowObject.getObjotype())) {
                oidSet.add(ruFlowObject.getOid());
            }
        }

        this.typlmRuFlowObjectService.delete(oidSet);
    }

    private WorkFlowContainer findRootWorkFlowContainer(WorkFlowContainer workFlowContainer) {
        if (TyAccountContext.isDebug()) {
            log.info("findRootWorkFlowContainer 方法入参workFlowContainer ==> 【{}】", JSONObject.toJSONString(workFlowContainer));
        }

        String rootFlowableProcessId = workFlowContainer.getRootFlowableProcessId();
        if (StringUtils.isNotBlank(rootFlowableProcessId)) {
            workFlowContainer = this.typlmWorkFlowContainerService.getWorkFlowContainerByFlowableProcessId(rootFlowableProcessId);
            workFlowContainer = this.findRootWorkFlowContainer(workFlowContainer);
        }

        return workFlowContainer;
    }

    public void updateState(WorkFlowContainer workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "updateState 方法入参workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
        List<FlowObjectPackageLink> listByPackage = this.typlmFlowObjectPackageLinkService.getListByPackage(workFlowContainer.getBaseObjectOid(), workFlowContainer.getBaseObjectOtype());
        List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.batchUpdateLast(listByPackage);
        if (flowObjectList != null) {
            for(FlowObject flowObject : flowObjectList) {
                this.setProcessObjectLife(flowObject);
                this.typlmLifecycleStageService.updateLifeCycleState(flowObject.getRefObjectOid(), flowObject.getRefObjectOtype(), flowObject.getTargetStatusKey(), flowObject.getTargetStatusOid(), flowObject.getTargetStatusOtype());
            }
        }

    }

    private void setProcessObjectLife(FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "setProcessObjectLife 方法入参flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject)});
        if (!Objects.isNull(flowObject) && !StringUtils.isBlank(flowObject.getTargetStatusKey())) {
            List<String> selectPreferenceValueList = Collections.singletonList("flow_updatestate_all");
            Map<String, Object> preferenceCollectRulesMap = this.typlmPreferenceValueUtil.readPreferenceValueByKeywords(selectPreferenceValueList);
            boolean flowUpdatestateAll = QueryDownloadDocUtil.getBooleanValueByObject(preferenceCollectRulesMap.get("flow_updatestate_all"));
            log.info(">>>>>flowUpdatestateAll:" + flowUpdatestateAll + "userid:" + CommonUtil.getUserOid());
            if (flowUpdatestateAll && (flowObject.getRefObjectOtype().equals("ty.inteplm.mpm.CTyMPMProcessPlan") || flowObject.getRefObjectOtype().equals("ty.inteplm.mpm.CTyMPMOperation"))) {
                List<JSONObject> list = new ArrayList();
                TyplmGeneralOperationDTO goDTO = new TyplmGeneralOperationDTO();
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("oid", flowObject.getRefObjectOid());
                jsonObject.put("otype", flowObject.getRefObjectOtype());
                List<JSONObject> currentObj = new ArrayList();
                currentObj.add(jsonObject);
                goDTO.setCurrentObj(currentObj);
                this.tymMpmWorkFlowAdaptationService.getAllObjWorkFlow(goDTO, list);
                if (CollUtil.isNotEmpty(list)) {
                    for(JSONObject object : list) {
                        this.typlmLifecycleStageService.updateLifeCycleState(object.getBigInteger("oid"), object.getString("otype"), flowObject.getTargetStatusKey(), flowObject.getTargetStatusOid(), flowObject.getTargetStatusOtype());
                    }
                }
            }

        }
    }

    private void updateObjectLink(WorkFlowObjectPackage workFlowObjectPackage, List<FlowObject> objList) {
        this.updateObjectLink(workFlowObjectPackage, objList, true);
    }

    private void addRelationDoc(String partId, List<BaseObject> objList) {
        this.addRelationDoc(partId, objList, true);
    }

    private void addRelationDoc(String partId, List<BaseObject> objList, boolean flag) {
        TyplmLoggerUtil.debug(log, () -> "addRelationDoc 方法入参partId ==> 【{}】;objList ==> 【{}】; flag ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(partId), JSONObject.toJSONString(objList), JSONObject.toJSONString(flag)});
        List<DocDetails> partLinkDescribeDoc = this.typlmPdmPartService.getPartLinkDescribeDoc(partId);
        if (ObjectUtils.isNotEmpty(partLinkDescribeDoc)) {
            for(DocDetails describe : partLinkDescribeDoc) {
                BaseObject describeDoc = new BaseObject();
                if (!flag || this.isAddWorkFlow(describe.getLifecycleState(), describe.getCreatorName())) {
                    describeDoc.setOid(new BigInteger(describe.getOid()));
                    describeDoc.setOtype(describe.getOtype());
                    objList.add(describeDoc);
                }
            }
        }

        List<DocDetails> partLinkReferenceDoc = this.typlmPdmPartService.getPartLinkReferenceDoc(partId);
        if (ObjectUtils.isNotEmpty(partLinkReferenceDoc)) {
            for(DocDetails reference : partLinkReferenceDoc) {
                BaseObject referenceDoc = new BaseObject();
                if (!flag || this.isAddWorkFlow(reference.getLifecycleState(), reference.getCreatorName())) {
                    referenceDoc.setOid(new BigInteger(reference.getOid()));
                    referenceDoc.setOtype(reference.getOtype());
                    objList.add(referenceDoc);
                }
            }
        }

    }

    private void updateObjectLink(WorkFlowObjectPackage workFlowObjectPackage, List<FlowObject> objList, boolean flag) {
        if (TyAccountContext.isDebug()) {
            log.info("updateObjectLink 方法入参workFlowObjectPackage ==> 【{}】;objList ==> 【{}】; flag ==> 【{}】", new Object[]{JSONObject.toJSONString(workFlowObjectPackage), JSONObject.toJSONString(objList), JSONObject.toJSONString(flag)});
        }

        if (objList == null) {
            objList = new ArrayList();
        }

        this.tymMpmWorkFlowAdaptationService.setAssignmentsMpmChildData(objList);
        BigInteger packageOid = workFlowObjectPackage.getBaseObjectOid();
        String packageOtype = workFlowObjectPackage.getBaseObjectOtype();
        List<FlowObjectPackageLink> listByPackage = this.typlmFlowObjectPackageLinkService.getListByPackage(packageOid, packageOtype);
        Map<BigInteger, FlowObjectPackageLink> flowObjMap = (Map)listByPackage.stream().collect(Collectors.toMap(FlowObjectPackageLink::getOid, (flowObjectPackageLink) -> flowObjectPackageLink));

        for(FlowObject flowObject : objList) {
            BigInteger oid = flowObject.getOid();
            flowObject.setPackageOid(packageOid);
            flowObject.setPackageOtype(packageOtype);
            if (oid != null && BigInteger.ZERO.compareTo(oid) != 0 && flowObjMap.containsKey(oid)) {
                this.typlmFlowObjectPackageLinkService.update(flowObject);
            } else if (flag) {
                this.typlmFlowObjectPackageLinkService.insert(flowObject);
            }

            flowObjMap.remove(oid);
        }

        if (flag) {
            for(FlowObjectPackageLink value : flowObjMap.values()) {
                this.typlmFlowObjectPackageLinkService.delete(value.getOid());
            }

        }
    }

    public List<FlowObject> filterFlowObjectList(List<FlowObject> flowObjectList, FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "filterFlowObjectList 方法入参flowObjectList ==> 【{}】;flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList), JSONObject.toJSONString(flowTaskInfo)});
        Task task = this.typlmFlowElementService.getNonTask(flowTaskInfo.getTaskId());
        boolean containerViewNeedDistributeObjects = this.typlmFlowElementService.checkContainerViewNeedDistributeObjects(task);
        TyplmLoggerUtil.debug(log, () -> "filterFlowObjectList 检查流程视图是否需要分配内容 containerViewNeedDistributeObjects==> 【{}】", () -> new Object[]{JSONObject.toJSONString(containerViewNeedDistributeObjects)});
        if (containerViewNeedDistributeObjects) {
            List<FlowObject> flowObjectListNew = new ArrayList();

            for(FlowObject flowObject : flowObjectList) {
                String taskDefKey = flowObject.getTaskdefkey();
                if (StringUtils.isNotBlank(taskDefKey)) {
                    List<String> taskDefKeyList = (List)Arrays.asList(taskDefKey.split(",")).stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
                    if (taskDefKeyList.contains(task.getTaskDefinitionKey())) {
                        flowObjectListNew.add(flowObject);
                    }
                }
            }

            return flowObjectListNew;
        } else {
            return flowObjectList;
        }
    }

    private List<String> checkStatus(List<String> errorMessageList, FlowTaskInfo flowTaskInfo) {
        TyplmLoggerUtil.debug(log, () -> "checkStatus 方法入参errorMessageList ==> 【{}】; flowTaskInfo ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(errorMessageList), JSONObject.toJSONString(flowTaskInfo)});
        if (flowTaskInfo == null) {
            return errorMessageList;
        } else {
            WorkFlowContainerView workFlowContainerView = flowTaskInfo.getWorkFlowContainerView();
            if (workFlowContainerView == null) {
                return errorMessageList;
            } else {
                List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(workFlowContainerView.getBaseObjectOid(), workFlowContainerView.getBaseObjectOtype());
                flowObjectList = this.filterFlowObjectList(flowObjectList, flowTaskInfo);
                return checkStatus(errorMessageList, flowObjectList);
            }
        }
    }

    private List<String> checkStatus(BigInteger objectOid, String objectOtype, List<String> errorMessageList) {
        TyplmLoggerUtil.debug(log, () -> "checkStatus 方法入参objectOid ==> 【{}】; objectOtype ==> 【{}】; errorMessageList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objectOid), objectOtype, JSONObject.toJSONString(errorMessageList)});
        List<FlowObjectPackageLink> listByPackage = this.typlmFlowObjectPackageLinkService.getListByPackage(objectOid, objectOtype);
        List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.batchUpdateLast(listByPackage);
        return checkStatus(errorMessageList, flowObjectList);
    }

    private static List<String> checkStatus(List<String> errorMessageList, List<FlowObject> flowObjectList) {
        TyplmLoggerUtil.debug(log, () -> "checkStatus 方法入参errorMessageList ==> 【{}】; flowObjectList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(errorMessageList), JSONObject.toJSONString(flowObjectList)});
        if (CollectionUtils.isEmpty(flowObjectList)) {
            return errorMessageList;
        } else {
            for(FlowObject flowObject : flowObjectList) {
                if (StringUtils.isNotBlank(flowObject.getLockStateInfo()) && !"c/i".equals(flowObject.getLockStateInfo())) {
                    errorMessageList.add(flowObject.getRefObjectName() + "被检出，不能启动流程或者完成任务！");
                }
            }

            return errorMessageList;
        }
    }

    private void dealChildrenPart(HashSet<PartBomTree> set, List<BaseObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "dealChildrenPart 方法入参set ==> 【{}】; objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(set), JSONObject.toJSONString(objList)});

        for(PartBomTree partBomTree : set) {
            BaseObject part = new BaseObject();
            String lifecycleState = partBomTree.getLifecycleState();
            String creator = partBomTree.getCreateName();
            boolean flag = this.isAddWorkFlow(lifecycleState, creator);
            if (flag) {
                part.setOid(new BigInteger(partBomTree.getPartoid()));
                part.setOtype(partBomTree.getPartotype());
                objList.add(part);
            }

            this.addRelationDoc(partBomTree.getPartoid(), objList);
            if (ObjectUtils.isNotEmpty(partBomTree.getChildren())) {
                this.dealChildrenPart(partBomTree.getChildren(), objList);
            }
        }

    }

    private boolean isAddWorkFlow(String lifecycleState, String creator) {
        TyplmLoggerUtil.debug(log, () -> "isAddWorkFlow 方法入参lifecycleState ==> 【{}】; creator ==> 【{}】", () -> new Object[]{lifecycleState, creator});
        String userName = CommonUtil.getCurrentUserName();
        ArgumentUtils.checkArgumentNull(userName, "用户未登录！");
        if (!creator.equals(userName)) {
            return false;
        } else {
            return !StringUtils.isBlank(this.state) && this.state.equals(lifecycleState);
        }
    }

    private void setDocInfo(FlowObject flowObject, BigInteger objId, String objType) {
        TyplmLoggerUtil.debug(log, () -> "setDocInfo 方法入参flowObject ==> 【{}】; objId ==> 【{}】; objType ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject), JSONObject.toJSONString(objId), objType});
        DocDetails docDetails = this.typlmDocumentService.queryDocDetails(objId, objType);
        flowObject.setMasterId(docDetails.getTypeOid());
        TypeDO typeEObj = this.typlmTypeService.queryTypeByOID(new BigInteger(docDetails.getTypeOid()));
        flowObject.setMasterId(typeEObj.getMasteredoid().toString());
        flowObject.setLifeCycleStageKey(docDetails.getLifecycleStateKey());
    }

    private void setPartInfo(FlowObject flowObject, BigInteger objId, String objType) {
        TyplmLoggerUtil.debug(log, () -> "setPartInfo 方法入参flowObject ==> 【{}】; objId ==> 【{}】; objType ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject), JSONObject.toJSONString(objId), objType});
        PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(objId, objType);
        TypeDO typeEObj = this.typlmTypeService.queryTypeByOID(new BigInteger(partDetailsVO.getTypeOid()));
        flowObject.setMasterId(typeEObj.getMasteredoid().toString());
        flowObject.setLifeCycleStageKey(partDetailsVO.getLifecycleStateKey());
    }

    private void setProcessPlanInfo(FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "setProcessPlanInfo 方法入参flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject)});
        TyplmMpmProcessPlanAdaptationService mpmPlanService = (TyplmMpmProcessPlanAdaptationService)TySpringBeanUtil.getBean(TyplmMpmProcessPlanAdaptationService.class);
        TyplmGeneralOperationDTO operationEObj = new TyplmGeneralOperationDTO();
        JSONObject params = new JSONObject();
        params.put("oid", flowObject.getRefObjectOid());
        params.put("sotype", "ty.inteplm.mpm.CTyMPMProcessPlan");
        operationEObj.getCurrentObj().add(params);
        TyplmMpmCommonAdaptationService mpmCommonService = (TyplmMpmCommonAdaptationService)TySpringBeanUtil.getBean(TyplmMpmCommonAdaptationService.class);
        TyplmProcessPlanVo processPlanFromData = mpmPlanService.getTyplmProcessPlanInfo(operationEObj);
        JSONObject data = mpmCommonService.getPlanInfo(processPlanFromData, operationEObj);
        TypeDO typeEObj = this.typlmTypeService.queryTypeByOID(data.getBigInteger("typeoid"));
        flowObject.setMasterId(typeEObj.getMasteredoid().toString());
        flowObject.setLifeCycleStageKey(data.getString("lifecyclestagekey"));
    }

    private void setFormDataInfo(FlowObject flowObject, BigInteger objId) {
        TyplmLoggerUtil.debug(log, () -> "setFormDataInfo 方法入参flowObject ==> 【{}】; objId ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject), JSONObject.toJSONString(objId)});
        FormDataVO formData = this.typlmFormDataService.getFormData(objId);
        TypeDO typeEObj = this.typlmTypeService.queryTypeByOID(formData.getTypeoid());
        flowObject.setMasterId(typeEObj.getMasteredoid().toString());
        flowObject.setLifeCycleStageKey(formData.getLifecyclestagekey());
    }

    private void setOperationInfo(FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "setOperationInfo 方法入参flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObject)});
        TyplmMpmOperationAdaptationService mpmOperationService = (TyplmMpmOperationAdaptationService)TySpringBeanUtil.getBean(TyplmMpmOperationAdaptationService.class);
        TyplmMpmCommonAdaptationService mpmCommonService = (TyplmMpmCommonAdaptationService)TySpringBeanUtil.getBean(TyplmMpmCommonAdaptationService.class);
        JSONObject params = new JSONObject();
        TyplmGeneralOperationDTO operationEObj = new TyplmGeneralOperationDTO();
        params.put("oid", flowObject.getRefObjectOid());
        operationEObj.getCurrentObj().add(params);
        params.put("sotype", "ty.inteplm.mpm.CTyMPMProcessPlan");
        params.put("typeotype", flowObject.getRefObjectOtype());
        JSONObject data = mpmOperationService.getOperationInfo(operationEObj);
        Map<String, Object> mapConfig = new HashMap();
        data = mpmCommonService.entityChangeJsonToLowerCase(data, mapConfig);
        TypeDO typeEObj = this.typlmTypeService.queryTypeByOID(data.getBigInteger("typeoid"));
        flowObject.setMasterId(typeEObj.getMasteredoid().toString());
        flowObject.setLifeCycleStageKey(data.getString("lifecyclestagekey"));
    }

    public List<? extends BaseFlowObjectTask> getBaseFlowObjectTask(WorkFlowContainer workFlowContainer) {
        return this.typlmFlowObjectPackageLinkService.getListByPackage(workFlowContainer.getBaseObjectOid(), workFlowContainer.getBaseObjectOtype());
    }

    public Map<IdentifierEntity, List<IdentifierEntity>> getFlowObjectMap(WorkFlowContainer workFlowContainer, String taskDefKey, boolean needDistributeObjects) {
        TyplmLoggerUtil.debug(log, () -> "getFlowObjectMap 方法入参workFlowContainer ==> 【{}】; taskDefKey ==> 【{}】;  needDistributeObjects ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer), taskDefKey, JSONObject.toJSONString(needDistributeObjects)});
        IdentifierEntity baseEntity = new IdentifierEntity(workFlowContainer.getBaseObjectOid(), workFlowContainer.getBaseObjectOtype());
        TyAccountContext.setIgnoreAuth(true);
        List<FlowObject> flowObjectList = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(workFlowContainer.getBaseObjectOid(), workFlowContainer.getBaseObjectOtype());
        flowObjectList = this.filterFlowObjectList(flowObjectList, taskDefKey, needDistributeObjects);
        Map<IdentifierEntity, List<IdentifierEntity>> map = Maps.newHashMap();
        if (ObjectUtils.isEmpty(flowObjectList)) {
            map.put(baseEntity, new ArrayList());
            return map;
        } else {
            List<IdentifierEntity> relativeIdentifierList = (List)flowObjectList.stream().filter((item) -> Objects.nonNull(item) && !TyplmEntityBaseUtil.isEmptyOid(item.getRefObjectOid()) && StringUtils.isNotBlank(item.getRefObjectOtype())).map((item) -> new IdentifierEntity(item.getRefObjectOid(), item.getRefObjectOtype())).distinct().collect(Collectors.toList());
            if (ObjectUtils.isEmpty(relativeIdentifierList)) {
                map.put(baseEntity, new ArrayList());
                return map;
            } else {
                map.put(baseEntity, relativeIdentifierList);
                return map;
            }
        }
    }

    public Map<IdentifierEntity, List<IdentifierEntity>> getFlowSignObjectMap(WorkFlowContainer workFlowContainer, String taskDefKey, boolean needDistributeObjects) {
        return this.getFlowObjectMap(workFlowContainer, taskDefKey, needDistributeObjects);
    }

    public List<WorkFlowObjectDTO> getRelationObject(WorkFlowContainer workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "getRelationObject 方法入参workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
        List<WorkFlowObjectDTO> result = new ArrayList();
        BigInteger baseObjectOid = workFlowContainer.getBaseObjectOid();
        String baseObjectOtype = workFlowContainer.getBaseObjectOtype();
        if (ObjectUtils.isEmpty(baseObjectOid) && StringUtils.isBlank(baseObjectOtype)) {
            return result;
        } else {
            List<FlowObjectPackageLink> packageLinks = this.typlmFlowObjectPackageLinkService.getListByPackage(baseObjectOid, baseObjectOtype);
            if (CollUtil.isNotEmpty(packageLinks)) {
                Map<BigInteger, String> typeMap = new HashMap();
                Map<String, Object> requestContext = RequestContext.currentContext();
                packageLinks.parallelStream().forEach((item) -> {
                    RequestContext.attachContext(requestContext);
                    WorkFlowObjectDTO workFlowObjectDTO = new WorkFlowObjectDTO();
                    workFlowObjectDTO.setRefObjectOid(item.getRefObjectOid());
                    workFlowObjectDTO.setRefObjectOtype(item.getRefObjectOtype());
                    IdentifierEntity identifierEntity = new IdentifierEntity();
                    identifierEntity.setOid(workFlowObjectDTO.getRefObjectOid());
                    identifierEntity.setOtype(workFlowObjectDTO.getRefObjectOtype());
                    CTyEntityBaseDO entity = CommonUtil.getEntity(identifierEntity);
                    String typeDefName = this.getAttachmentTypeName(entity, typeMap);
                    if (StringUtils.isEmpty(typeDefName)) {
                        workFlowObjectDTO.setRefObjectName(CommonUtil.getEntityDisplayName(entity));
                    } else {
                        workFlowObjectDTO.setRefObjectName(typeDefName + ":" + CommonUtil.getEntityDisplayName(entity));
                    }

                    result.add(workFlowObjectDTO);
                });
            }

            return result;
        }
    }

    public WorkFlowContainerView getEmptyContainerView(IdentifierEntity entity) {
        return new WorkFlowObjectPackage();
    }

    public WorkFlowContainerView createContainerView(WorkFlowContainerView inputContainerView) {
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)TyplmWorkFlowUtil.parseContainerView(inputContainerView, WorkFlowObjectPackage.class);
        this.insert(workFlowObjectPackage);
        addAuditLog(workFlowObjectPackage);
        return workFlowObjectPackage;
    }

    private static void addAuditLog(WorkFlowObjectPackage workFlowObjectPackage) {
        List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
        if (!CollectionUtils.isEmpty(flowObjectList)) {
            for(FlowObject flowObject : flowObjectList) {
                TyplmAuditLogUtil.info(flowObject.getRefObjectOid(), flowObject.getRefObjectOtype(), LogEventEnum.ADD_TO_WORKFLOW);
            }

        }
    }

    public WorkFlowContainerView updateContainerView(HttpServletRequest request) {
        WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage)JSON.parseObject(request.getParameter("param"), WorkFlowObjectPackage.class);
        workFlowObjectPackage.setCode(workFlowObjectPackage.getCodeNumber());
        this.update(workFlowObjectPackage);
        return workFlowObjectPackage;
    }

    private String getAttachmentTypeName(CTyEntityBaseDO cTyEntityBaseDO, Map<BigInteger, String> typeMap) {
        TyplmLoggerUtil.debug(log, () -> "getAttachmentTypeName 方法入参cTyEntityBaseDO ==> 【{}】; typeMap ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(cTyEntityBaseDO), JSONObject.toJSONString(typeMap)});
        String typeDefName = null;
        if (cTyEntityBaseDO instanceof ITyTyped) {
            BigInteger typeoid = ((ITyTyped)cTyEntityBaseDO).getTypeoid();
            if (!EntityBaseUtil.isEmptyOid(typeoid)) {
                if (typeMap.containsKey(typeoid)) {
                    typeDefName = (String)typeMap.get(typeoid);
                } else {
                    List<TypeVueVO> list = this.typlmTypeService.queryTypeByIds(Collections.singletonList(typeoid));
                    if (!CollectionUtils.isEmpty(list)) {
                        TypeVueVO type = (TypeVueVO)list.get(0);
                        typeDefName = type.getDisplayName();
                        typeMap.put(typeoid, typeDefName);
                    }
                }
            }
        }

        if (StringUtils.isEmpty(typeDefName)) {
            typeDefName = TyplmEntityBaseUtil.getOtypeDisplayName(cTyEntityBaseDO.getOtype());
        }

        return typeDefName;
    }

    private List<FlowObject> filterFlowObjectList(List<FlowObject> flowObjectList, String taskDefKey, boolean needDistributeObjects) {
        TyplmLoggerUtil.debug(log, () -> "filterFlowObjectList 方法入参flowObjectList ==> 【{}】; taskDefKey ==> 【{}】;  needDistributeObjects ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList), taskDefKey, JSONObject.toJSONString(needDistributeObjects)});
        if (!needDistributeObjects) {
            return flowObjectList;
        } else {
            List<FlowObject> flowObjectListNew = new ArrayList();

            for(FlowObject flowObject : flowObjectList) {
                if (ObjectUtils.isNotEmpty(flowObject.getTaskdefkey()) && flowObject.getTaskdefkey().contains(taskDefKey)) {
                    flowObjectListNew.add(flowObject);
                }
            }

            return flowObjectListNew;
        }
    }

    public WorkFlowObjectPackage checkObjListEnableStart(List<BaseObject> objList, BigInteger containerOid, String containerOtype) {
        TyplmLoggerUtil.debug(log, () -> "checkObjListEnableStart 方法入参objList ==> 【{}】; containerOid ==> 【{}】;  containerOtype ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(containerOid), containerOtype});
        List<FlowObject> flowObjectList = this.baseObjectToFlowObject(objList);
        List<WorkFlow> workFlows = this.queryWorkflowByFlowObjectList(flowObjectList, containerOid, containerOtype);
        if (CollectionUtils.isEmpty(workFlows)) {
            throw WorkFlowErrorCodeEnum.THIS_TYPE_AND_LIFE_CYCLE_NO_BIND_WORK_FLOW.getException(new Object[0]);
        } else {
            WorkFlowObjectPackage workFlowObjectPackage = new WorkFlowObjectPackage();
            if (workFlows.size() == 1) {
                workFlowObjectPackage.setWorkFlowId(((WorkFlow)workFlows.get(0)).getOid());
            }

            if (CollUtil.isNotEmpty(flowObjectList)) {
                this.setBaseLineObject(flowObjectList);
            }

            workFlowObjectPackage.setContainerOid(containerOid);
            workFlowObjectPackage.setContainerOtype(containerOtype);
            workFlowObjectPackage.setFlowObjectList(flowObjectList);
            workFlowObjectPackage.setBaseObjectOtype(this.getType());
            return workFlowObjectPackage;
        }
    }

    public List<FlowObject> addCheckObjListEnableStart(List<BaseObject> objList, BigInteger workFlowContainerId) {
        TyplmLoggerUtil.debug(log, () -> "addCheckObjListEnableStart 方法入参objList ==> 【{}】; workFlowContainerId ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(workFlowContainerId)});
        Map<String, Set<BigInteger>> refObjectOidMap = new HashMap();
        List<BaseObject> inProcessObjList = this.filterObjListInContainer(workFlowContainerId, refObjectOidMap);
        return this.collectCheckObj(objList, workFlowContainerId, inProcessObjList);
    }

    private List<FlowObject> baseObjectToFlowObject(List<BaseObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "baseObjectToFlowObject 方法入参objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        return this.baseObjectToFlowObject(objList, true);
    }

    private List<FlowObject> baseObjectToFlowObject(List<BaseObject> objList, boolean checkStart) {
        TyplmLoggerUtil.debug(log, () -> "baseObjectToFlowObject 方法入参objList ==> 【{}】; checkStart ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(checkStart)});
        List<String> errorMessageList = new CopyOnWriteArrayList();
        List<FlowObject> flowObjectList = new CopyOnWriteArrayList();
        Map<String, List<BaseObject>> objMap = (Map)objList.stream().collect(Collectors.groupingBy(IdentifierEntity::getOtype));
        TyplmLoggerUtil.debug(log, () -> "baseObjectToFlowObject 将对象按照otype分组 objMap==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objMap)});
        objMap.entrySet().stream().forEach((entry) -> {
            String otype = (String)entry.getKey();
            List<String> oidList = (List)((List<BaseObject>)entry.getValue()).stream().map((baseObject) -> baseObject.getOid().toString()).collect(Collectors.toList());
            List<CTyEntityBaseDO> entityList = CommonUtil.getEntitys(otype, oidList);
            TyplmLoggerUtil.debug(log, () -> "baseObjectToFlowObject 收集对象功能，需要一次添加大量对象：同类型对象，批量校验对象是否在流程中 entityList==> 【{}】", () -> new Object[]{JSONObject.toJSONString(entityList)});
            Map<String, Boolean> stringBooleanMap;
            if (checkStart) {
                stringBooleanMap = this.typlmFlowContainerObjectService.batchCheckEntityListInActiveFlowContainer(entityList, otype);
            } else {
                stringBooleanMap = null;
            }

            if (TyAccountContext.isDebug()) {
                log.info("baseObjectToFlowObject 校验结果 stringBooleanMap==> 【{}】", JSONObject.toJSONString(stringBooleanMap));
            }

            Map<String, Object> requestContext = RequestContext.currentContext();
            entityList.parallelStream().forEach((entity) -> {
                RequestContext.attachContext(requestContext);
                FlowObject flowObject = new FlowObject();
                BigInteger refObjectOid = entity.getOid();
                String refObjectOtype = entity.getOtype();
                String refObjectName = entity.getName();
                List<BigInteger> list = new ArrayList();
                if (entity instanceof ITyContained) {
                    ITyContained iTyContained = (ITyContained)entity;
                    flowObject.setContainerOid(iTyContained.getContaineroid());
                    flowObject.setContainerOtype(iTyContained.getContainerotype());
                }

                this.handleTyped(entity, flowObject, list);
                refObjectName = this.setProcessObject(flowObject, entity, refObjectOtype, refObjectName);
                flowObject.setRefObjectOid(refObjectOid);
                flowObject.setRefObjectOtype(refObjectOtype);
                flowObject.setRefObjectName(refObjectName);
                if (checkStart && Boolean.TRUE.equals(stringBooleanMap.get(refObjectOid.toString()))) {
                    errorMessageList.add(CommonUtil.getEntityDisplayName(entity) + "所处流程未开启或正在流程中");
                } else {
                    if (checkStart) {
                        if (this.handleIterated(errorMessageList, entity, flowObject)) {
                            return;
                        }
                    } else if (entity instanceof ITyIterated) {
                        ITyIterated obj = (ITyIterated)entity;
                        flowObject.setMasteredoid(obj.getMasteredoid());
                        flowObject.setBranchId(obj.getBranchid());
                        flowObject = this.typlmFlowObjectPackageLinkService.updateLast(flowObject);
                    }

                    this.handleLifeCycleManaged(entity, flowObject);
                    flowObjectList.add(flowObject);
                }
            });
        });
        if (!errorMessageList.isEmpty()) {
            String errorMessage = String.join(";", errorMessageList);
            throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{errorMessage});
        } else {
            if (CollUtil.isNotEmpty(flowObjectList)) {
                this.setBaseLineObject(flowObjectList);
            }

            return flowObjectList;
        }
    }

    public void handleLifeCycleManaged(CTyEntityBaseDO entity, FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "handleLifeCycleManaged 方法入参entity ==> 【{}】; flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(entity), JSONObject.toJSONString(flowObject)});
        if (entity instanceof ITyLifeCycleManaged) {
            ITyLifeCycleManaged obj = (ITyLifeCycleManaged)entity;
            String lifecycleStageKey = obj.getLifecyclestagekey();
            flowObject.setLifeCycleStageKey(lifecycleStageKey);
            flowObject.setOriginalStatusKey(lifecycleStageKey);
            flowObject.setOriginalStatusOid(obj.getLifecyclestageoid());
            flowObject.setOriginalStatusOtype(obj.getLifecyclestageotype());
            BigInteger lifecycleTemplateOid = obj.getLifecycletemplateoid();
            flowObject.setLifecycleTemplateOid(lifecycleTemplateOid);
            this.typlmFlowObjectPackageService.flowObjectSetLifecycleStageInfo(flowObject, lifecycleStageKey, lifecycleTemplateOid, false);
        }
    }

    private boolean handleIterated(List<String> errorMessageList, CTyEntityBaseDO entity, FlowObject flowObject) {
        TyplmLoggerUtil.debug(log, () -> "handleIterated 方法入参errorMessageList ==> 【{}】;entity ==> 【{}】; flowObject ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(errorMessageList), JSONObject.toJSONString(entity), JSONObject.toJSONString(flowObject)});
        if (!(entity instanceof IteratorEntity)) {
            return false;
        } else {
            IteratorEntity obj = (IteratorEntity)entity;
            Long latest = obj.getIslastiterated();
            String lockStateInfo = obj.getLockstateinfo();
            if (latest != null && latest != 0L) {
                if (!"c/o".equals(lockStateInfo) && !"wrk".equals(lockStateInfo)) {
                    flowObject.setMasteredoid(obj.getMasteredoid());
                    flowObject.setBranchId(obj.getBranchid());
                    this.typlmFlowObjectPackageLinkService.setFlowObjectIteratorInfo(flowObject, obj);
                    return false;
                } else {
                    errorMessageList.add(this.getEntityDisplayName(entity) + "为检出状态");
                    return true;
                }
            } else {
                errorMessageList.add(this.getEntityDisplayName(entity) + "不是最新版本");
                return true;
            }
        }
    }

    private String getEntityDisplayName(CTyEntityBaseDO entity) {
        TyplmLoggerUtil.debug(log, () -> "getEntityDisplayName 方法入参entity ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(entity)});
        String typeDefName = this.getExceptionMessage(entity);
        String name = CommonUtil.getEntityDisplayName(entity);
        return StringUtils.isNotBlank(typeDefName) ? typeDefName + ":" + name : name;
    }

    private String getExceptionMessage(CTyEntityBaseDO entity) {
        TyplmLoggerUtil.debug(log, () -> "getExceptionMessage 方法入参entity ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(entity)});
        if (!(entity instanceof ITyTyped)) {
            return "";
        } else {
            BigInteger typeOid = ((ITyTyped)entity).getTypeoid();
            if (EntityBaseUtil.isEmptyOid(typeOid)) {
                return "";
            } else {
                List<TypeVueVO> typeVueList = this.typlmTypeService.queryTypeByIds(Collections.singletonList(typeOid));
                return ObjectUtils.isEmpty(typeVueList) ? "" : ((TypeVueVO)typeVueList.get(0)).getDisplayName();
            }
        }
    }

    public void handleTyped(CTyEntityBaseDO entity, FlowObject flowObject, List<BigInteger> list) {
        TyplmLoggerUtil.debug(log, () -> "handleTyped 方法入参entity ==> 【{}】;flowObject ==> 【{}】; list ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(entity), JSONObject.toJSONString(flowObject), JSONObject.toJSONString(list)});
        if (entity instanceof ITyTyped) {
            BigInteger typeoid = ((ITyTyped)entity).getTypeoid();
            flowObject.setTypeOid(typeoid);
            TypeDO typeDO = this.typlmTypeService.queryTypeByOID(typeoid);
            if (typeDO != null) {
                List<BigInteger> listType = new ArrayList();
                listType.add(typeDO.getMasteredoid());
                TypeDO parentTypeDO = this.typlmTypeService.queryTypeByOID(typeDO.getParentnodeoid());
                if (parentTypeDO == null) {
                    parentTypeDO = typeDO;
                }

                list.add(parentTypeDO.getMasteredoid());
                List<TypeVueVO> typeVueVOS = this.typlmTypeExtService.queryTypeByIds(Lists.newArrayList(new BigInteger[]{typeoid}));
                if (CollUtil.isNotEmpty(typeVueVOS)) {
                    TypeVueVO typeVueVO = (TypeVueVO)typeVueVOS.get(0);
                    flowObject.setCategory(typeVueVO.getDisplayName());
                    flowObject.setType(typeVueVO.getDisplayName());
                }

                flowObject.setMasterId(typeDO.getMasteredoid().toString());
            }
        }
    }

    private List<FlowObject> collectCheckObj(List<BaseObject> objList, BigInteger workFlowContainerId, List<BaseObject> inProcessObjList) {
        TyplmLoggerUtil.debug(log, () -> "collectCheckObj 方法入参objList ==> 【{}】;workFlowContainerId ==> 【{}】; inProcessObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList), JSONObject.toJSONString(workFlowContainerId), JSONObject.toJSONString(inProcessObjList)});
        if (!EntityBaseUtil.isEmptyOid(workFlowContainerId) && !ObjectUtils.isEmpty(inProcessObjList)) {
            List<BaseObject> addObjList = (List)objList.stream().filter((item) -> inProcessObjList.stream().noneMatch((data) -> data.getOid().equals(item.getOid()) && data.getOtype().equals(item.getOtype()))).collect(Collectors.toList());
            if (ObjectUtils.isEmpty(addObjList)) {
                return Collections.emptyList();
            } else {
                this.checkAddObjBasicInfo(addObjList);
                return this.baseObjectToFlowObject(addObjList);
            }
        } else {
            this.checkAddObjBasicInfo(objList);
            return this.baseObjectToFlowObject(objList);
        }
    }

    public List<BaseObject> filterObjListInContainer(BigInteger workFlowContainerId, Map<String, Set<BigInteger>> refObjectOidMap) {
        TyplmLoggerUtil.debug(log, () -> "filterObjListInContainer 方法入参workFlowContainerId ==> 【{}】;refObjectOidMap ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainerId), JSONObject.toJSONString(refObjectOidMap)});
        List<BaseObject> inProcessObjList = new ArrayList();
        if (workFlowContainerId != null && !BigInteger.ZERO.equals(workFlowContainerId)) {
            WorkFlowContainer workFlowContainer = (WorkFlowContainer)this.typlmWorkFlowContainerService.selectOneByOid(workFlowContainerId);
            TyplmLoggerUtil.debug(log, () -> "filterObjListInContainer 查询的流程容器 workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
            ArgumentUtils.checkArgumentEmpty(workFlowContainer, "流程");
            BigInteger packageOid = workFlowContainer.getBaseObjectOid();
            String packageOtype = workFlowContainer.getBaseObjectOtype();
            List<FlowObject> listByPackage = this.typlmFlowObjectPackageLinkService.getFlowObjectListByPackage(packageOid, packageOtype);
            TyplmLoggerUtil.debug(log, () -> "filterObjListInContainer 根据流程对象包查询对象列表 listByPackage ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(listByPackage)});
            inProcessObjList = (List)listByPackage.stream().map((item) -> {
                BaseObject baseObject = new BaseObject();
                baseObject.setOid(item.getRefObjectOid());
                baseObject.setOtype(item.getRefObjectOtype());
                return baseObject;
            }).collect(Collectors.toList());
            Map<String, List<FlowObject>> flowObjectMap = (Map)listByPackage.stream().collect(Collectors.groupingBy(FlowObjectPackageLink::getRefObjectOtype));

            for(Map.Entry<String, List<FlowObject>> flowObjectEntry : flowObjectMap.entrySet()) {
                String refOtype = (String)flowObjectEntry.getKey();
                List<FlowObject> refObjList = (List)flowObjectEntry.getValue();
                Set<BigInteger> refObjOidSet = (Set)refObjList.stream().map(FlowObjectPackageLink::getRefObjectOid).collect(Collectors.toSet());
                if (refObjectOidMap != null) {
                    refObjectOidMap.put(refOtype, refObjOidSet);
                }
            }

            return inProcessObjList;
        } else {
            return inProcessObjList;
        }
    }

    private void checkAddObjBasicInfo(List<BaseObject> newObjList) {
        TyplmLoggerUtil.debug(log, () -> "checkAddObjBasicInfo 方法入参newObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(newObjList)});
        List<IdentifierEntity> identityList = (List)newObjList.stream().map((item) -> new IdentifierEntity(item.getOid(), item.getOtype())).collect(Collectors.toList());
        Map<IdentifierEntity, CTyEntityBaseDO> entityMap = CommonUtil.getEntityMap(identityList);
        TyplmLoggerUtil.debug(log, () -> "checkAddObjBasicInfo 校验收集的对象 start");
        this.typlmCheckCollectionObjService.checkCollectObjCommonInfo(new ArrayList(entityMap.values()));
        TyplmLoggerUtil.debug(log, () -> "checkAddObjBasicInfo 校验收集的对象 end");
    }

    public String setProcessObject(FlowObject flowObject, CTyEntityBaseDO entity, String refObjectOtype, String refObjectName) {
        if (TyAccountContext.isDebug()) {
            log.info("setProcessObject 方法入参flowObject ==> 【{}】; entity ==> 【{}】; refObjectOtype ==> 【{}】; refObjectName ==> 【{}】", new Object[]{JSONObject.toJSONString(flowObject), JSONObject.toJSONString(entity), refObjectOtype, refObjectName});
        }

        if (refObjectOtype.equals("ty.inteplm.mpm.CTyMPMProcessPlan")) {
            flowObject.setTypeotype(((MPMProcessPlanDO)entity).getTypeotype());
        }

        if (refObjectOtype.equals("ty.inteplm.mpm.CTyMPMOperation")) {
            flowObject.setTypeotype(((MPMOperationDO)entity).getTypeotype());
        }

        if (refObjectOtype.equals("ty.inteplm.mpm.CTyMPMProcessPlan") || refObjectOtype.equals("ty.inteplm.mpm.CTyMPMOperation")) {
            String tablename = TyEntityMapperUtil.getTableNameByOtype(refObjectOtype);
            String masterOtype = TyEntityMapperUtil.getMasteredOtype(refObjectOtype);
            Mapper mapper = TyEntityMapperUtil.getMapperByOtype(masterOtype);
            Class<?> masterEntityClass = TyEntityMapperUtil.getClassByOtype(masterOtype);
            Example example = new Example(masterEntityClass, true, true);
            Example.Criteria criteria = example.createCriteria();
            criteria.andCondition("oid=(select masteredoid from " + tablename + " where oid=" + entity.getOid() + ")");
            List<CTyEntityBaseDO> listMaster = mapper.selectByExample(example);
            if (CollUtil.isNotEmpty(listMaster)) {
                refObjectName = ((CTyEntityBaseDO)listMaster.get(0)).getName();
            }
        }

        if (TyAccountContext.isDebug()) {
            log.info("setProcessObject 返回值refObjectName ==> 【{}】", refObjectName);
        }

        return refObjectName;
    }

    private void setBaseLineObject(List<FlowObject> objList) {
        TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 方法入参objList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(objList)});
        if (!CollUtil.isEmpty(objList)) {
            List<String> baseLineOidList = (List)objList.stream().filter((itemx) -> Objects.nonNull(itemx.getRefObjectOtype()) && Objects.nonNull(itemx.getRefObjectOid()) && itemx.getRefObjectOtype().equalsIgnoreCase("ty.inteplm.baseline.CTyBaseLine")).map((itemx) -> itemx.getRefObjectOid().toString()).collect(Collectors.toList());
            TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 过滤出基线对象的oid集合 baseLineOidList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(baseLineOidList)});
            if (!CollUtil.isEmpty(baseLineOidList)) {
                List<BaseLineDO> refObjList = this.typlmBaseLineService.queryBaseLineByoids(baseLineOidList);
                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 查询出对应的基线DO对象集合 refObjList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(refObjList)});
                List<BigInteger> typeOidList = (List)refObjList.stream().filter((vo) -> Objects.nonNull(vo.getTypeoid())).map(BaseLineDO::getTypeoid).distinct().collect(Collectors.toList());
                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 根据基线对象得到类型oid集合 typeOidList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(typeOidList)});
                List<String> lifecyclestagekeyList = (List)refObjList.stream().filter((vo) -> Objects.nonNull(vo.getLifecyclestagekey())).map(BaseLineDO::getLifecyclestagekey).distinct().collect(Collectors.toList());
                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 根据基线对象得到生命周期阶段集合 lifecyclestagekeyList ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(lifecyclestagekeyList)});
                Map<String, String> lifecycleCodeNameMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(lifecyclestagekeyList, "LifeCycleState", TyAccountContext.getLanguage());
                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 获取生命周期阶段的多语言 lifecycleCodeNameMap ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(lifecycleCodeNameMap)});
                Map<BigInteger, TypeVueVO> typeDisplayNameMap = new HashMap();
                if (CollUtil.isNotEmpty(typeOidList)) {
                    List<TypeVueVO> typeVueVOS = this.typlmTypeExtService.queryTypeByIds(typeOidList);
                    typeDisplayNameMap.putAll((Map)typeVueVOS.stream().collect(Collectors.toMap(TypeDO::getOid, (itemx) -> itemx, (k1, k2) -> k1)));
                }

                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 获取的类型 typeDisplayNameMap ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(typeDisplayNameMap)});
                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 遍历对象 start");

                for(FlowObject item : objList) {
                    BaseLineDO itemInfo = (BaseLineDO)refObjList.stream().filter((baselineInfo) -> item.getRefObjectOid().compareTo(baselineInfo.getOid()) == 0).findFirst().orElse(null);
                    if (Objects.nonNull(itemInfo)) {
                        item.setRefObjectNumber(itemInfo.getObjnumber());
                        item.setObjectNumber(itemInfo.getObjnumber());
                        item.setName(itemInfo.getName());
                        item.setCurrentStatusName((String)lifecycleCodeNameMap.getOrDefault(itemInfo.getLifecyclestagekey(), ""));
                        item.setErrorMarkFlag(0);
                        TypeVueVO typeInfo = (TypeVueVO)typeDisplayNameMap.getOrDefault(itemInfo.getTypeoid(), null);
                        if (Objects.nonNull(typeInfo)) {
                            item.setType(typeInfo.getDisplayName());
                        }
                    }

                    TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 设置完信息的FlowObject对象 item ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(item)});
                }

                TyplmLoggerUtil.debug(log, () -> "setBaseLineObject 遍历对象 end");
            }
        }
    }

    public WorkFlowObjectPackage checkWorkFlowStartRulesFillInfo(List<BaseObject> objList, BigInteger containerOid, String containerOtype, BaseObject firstObj) {
        WorkFlowObjectPackage workFlowContainer = this.checkWorkFlowStartRules(objList, containerOid, containerOtype);
        if ("ty.inteplm.part.CTyPart".equals(firstObj.getOtype())) {
            PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(firstObj.getOid(), firstObj.getOtype());
            this.setContainerByDomainId(partDetailsVO.getDomainoid(), workFlowContainer);
        }

        if ("ty.inteplm.cad.CTyCADDoc".equals(firstObj.getOtype()) || "ty.inteplm.doc.CTyDoc".equals(firstObj.getOtype())) {
            DocDetails docDetails = this.typlmDocumentService.queryDocDetails(firstObj.getOid(), firstObj.getOtype());
            this.setContainerByDomainId(docDetails.getDomainId(), workFlowContainer);
        }

        return workFlowContainer;
    }

    private void setContainerByDomainId(BigInteger domainId, WorkFlowObjectPackage workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "setContainerByDomainId 方法入参domainId ==> 【{}】; workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(domainId), JSONObject.toJSONString(workFlowContainer)});
        DomainDO domainEObj = this.typlmDomainService.queryDomainByOid(domainId);
        if (domainEObj == null) {
            throw WorkFlowErrorCodeEnum.DOMAIN_ID_NOT_EXIST.getException(new Object[]{domainId});
        } else {
            String name = this.typlmContainerService.getContainerName(domainEObj.getContaineroid(), domainEObj.getContainerotype());
            workFlowContainer.setContainerOid(domainEObj.getContaineroid());
            workFlowContainer.setContainerOtype(domainEObj.getContainerotype());
            workFlowContainer.setContainerName(name);
        }
    }

    public void checkFlowObjectContainsWorkFlow(List<FlowObject> flowObjectList, List<FlowObject> disabledAddList, BigInteger workflowId) {
        if (TyAccountContext.isDebug()) {
            log.info("checkFlowObjectContainsWorkFlow 校验流程包对象能够使用的流程模板中是否包含当前模板,方法入参flowObjectList ==> 【{}】; disabledAddList ==> 【{}】; workflowId ==> 【{}】", new Object[]{JSONObject.toJSONString(flowObjectList), JSONObject.toJSONString(disabledAddList), JSONObject.toJSONString(workflowId)});
        }

        if (!org.apache.commons.collections.CollectionUtils.isEmpty(flowObjectList)) {
            if (disabledAddList == null) {
                disabledAddList = new ArrayList();
            }

            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取流程对象的类型 start");
            Set<BigInteger> typeOidSet = Collections.synchronizedSet(new HashSet());
            Map<BigInteger, Set<FlowObject>> typeFlowObjectMap = new ConcurrentHashMap();
            flowObjectList.parallelStream().forEach((flowObjectx) -> {
                BigInteger typeOid = flowObjectx.getTypeOid();
                if (!EntityBaseUtil.isEmptyOid(typeOid)) {
                    typeOidSet.add(typeOid);
                    Set flowObjectSet = (Set)typeFlowObjectMap.computeIfAbsent(typeOid, (k) -> Collections.synchronizedSet(new HashSet()));
                    flowObjectSet.add(flowObjectx);
                }
            });
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取流程对象的类型 end,获取结果typeOidSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOidSet)});
            Set<BigInteger> typeOidAllSet = new HashSet();
            Map<BigInteger, List<BigInteger>> typeParentListMap = new HashMap();
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取所有父类型信息 start");
            this.typlmWorkFlowRuleService.getAllParentTypeOid(typeOidSet, typeOidAllSet, typeParentListMap);
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取所有父类型信息 end,获取结果typeOidAllSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOidAllSet)});
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 根据类型查询出全部的RULE start");
            Map<BigInteger, List<TypeWorkFlowRule>> workFlowRuleMap = this.typlmWorkFlowRuleService.getWorkFlowRuleMap(typeOidAllSet);
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 根据类型查询出全部的RULE end,获取结果workFlowRuleMap ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(workFlowRuleMap)});
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历类型 start");

            for(Map.Entry<BigInteger, List<BigInteger>> workFlowRuleEntry : typeParentListMap.entrySet()) {
                BigInteger typeOid = (BigInteger)workFlowRuleEntry.getKey();
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取对应类型的规则集合 start, typeOid ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOid)});
                Set<TypeWorkFlowRule> typeResultRuleSet = this.typlmWorkFlowRuleService.getTypeWorkFlowRules(workFlowRuleMap, workFlowRuleEntry, typeOid);
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取对应类型的规则集合 end,获取结果typeResultRuleSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeResultRuleSet)});
                Set<FlowObject> flowObjects = (Set)typeFlowObjectMap.get(typeOid);
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取到类型对于的流程对, flowObjects ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(flowObjects)});
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历流程对象 start");

                for(FlowObject flowObject : flowObjects) {
                    String lifeCycleStageKey = flowObject.getLifeCycleStageKey();
                    lifeCycleStageKey = lifeCycleStageKey == null ? "" : lifeCycleStageKey;
                    if (TyAccountContext.isDebug()) {
                        log.info("checkFlowObjectContainsWorkFlow 生命周期阶段key lifeCycleStageKey ==> 【{}】", lifeCycleStageKey);
                    }

                    boolean flag = true;

                    for(TypeWorkFlowRule typeWorkFlowRule : typeResultRuleSet) {
                        String lifeCycleStageKeys = typeWorkFlowRule.getLifeCycleStageKeys();
                        if (lifeCycleStageKeys.contains(lifeCycleStageKey)) {
                            BigInteger workFlowOid = typeWorkFlowRule.getWorkFlowOid();
                            if (workflowId.equals(workFlowOid)) {
                                flag = false;
                                break;
                            }
                        }
                    }

                    if (TyAccountContext.isDebug()) {
                        log.info("checkFlowObjectContainsWorkFlow 对象的类型找到模板是否包含当前模板 flag ==> 【{}】", JSONObject.toJSONString(!flag));
                    }

                    if (flag) {
                        flowObject.setDisabledAddReason(flowObject.getName() + "的流程模板不包含当前模板");
                        disabledAddList.add(flowObject);
                    }
                }

                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历流程对象 end");
            }

            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历类型 end");
        }
    }

    public void checkFlowObjectContainsWorkFlow(List<FlowObject> flowObjectList, BigInteger workflowId) {
        TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 校验流程包对象能够使用的流程模板中是否包含当前模板,方法入参flowObjectList ==> 【{}】; workflowId ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(flowObjectList), JSONObject.toJSONString(workflowId)});
        if (!org.apache.commons.collections.CollectionUtils.isEmpty(flowObjectList)) {
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取流程对象的类型 start");
            Set<BigInteger> typeOidSet = Collections.synchronizedSet(new HashSet());
            Map<BigInteger, Set<FlowObject>> typeFlowObjectMap = new ConcurrentHashMap();
            flowObjectList.parallelStream().forEach((flowObjectx) -> {
                BigInteger typeOid = flowObjectx.getTypeOid();
                if (!EntityBaseUtil.isEmptyOid(typeOid)) {
                    typeOidSet.add(typeOid);
                    Set flowObjectSet = (Set)typeFlowObjectMap.computeIfAbsent(typeOid, (k) -> Collections.synchronizedSet(new HashSet()));
                    flowObjectSet.add(flowObjectx);
                }
            });
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取流程对象的类型 end,获取结果typeOidSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOidSet)});
            Set<BigInteger> typeOidAllSet = new HashSet();
            Map<BigInteger, List<BigInteger>> typeParentListMap = new HashMap();
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取所有父类型信息 start");
            this.typlmWorkFlowRuleService.getAllParentTypeOid(typeOidSet, typeOidAllSet, typeParentListMap);
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取所有父类型信息 end,获取结果typeOidAllSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOidAllSet)});
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 根据类型查询出全部的RULE start");
            Map<BigInteger, List<TypeWorkFlowRule>> workFlowRuleMap = this.typlmWorkFlowRuleService.getWorkFlowRuleMap(typeOidAllSet);
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 根据类型查询出全部的RULE end,获取结果workFlowRuleMap ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(workFlowRuleMap)});
            Set<String> errorMessageSet = Collections.synchronizedSet(new HashSet());
            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历类型 start");

            for(Map.Entry<BigInteger, List<BigInteger>> workFlowRuleEntry : typeParentListMap.entrySet()) {
                BigInteger typeOid = (BigInteger)workFlowRuleEntry.getKey();
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取对应类型的规则集合 start, typeOid ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeOid)});
                Set<TypeWorkFlowRule> typeResultRuleSet = this.typlmWorkFlowRuleService.getTypeWorkFlowRules(workFlowRuleMap, workFlowRuleEntry, typeOid);
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取对应类型的规则集合 end,获取结果typeResultRuleSet ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(typeResultRuleSet)});
                Set<FlowObject> flowObjects = (Set)typeFlowObjectMap.get(typeOid);
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 获取到类型对于的流程对, flowObjects ==> 【{}】;", () -> new Object[]{JSONObject.toJSONString(flowObjects)});
                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历流程对象 start");

                for(FlowObject flowObject : flowObjects) {
                    String lifeCycleStageKey = flowObject.getLifeCycleStageKey();
                    lifeCycleStageKey = lifeCycleStageKey == null ? "" : lifeCycleStageKey;
                    if (TyAccountContext.isDebug()) {
                        log.info("checkFlowObjectContainsWorkFlow 生命周期阶段key lifeCycleStageKey ==> 【{}】", lifeCycleStageKey);
                    }

                    boolean flag = true;

                    for(TypeWorkFlowRule typeWorkFlowRule : typeResultRuleSet) {
                        String lifeCycleStageKeys = typeWorkFlowRule.getLifeCycleStageKeys();
                        if (lifeCycleStageKeys.contains(lifeCycleStageKey)) {
                            BigInteger workFlowOid = typeWorkFlowRule.getWorkFlowOid();
                            if (workflowId.equals(workFlowOid)) {
                                flag = false;
                                break;
                            }
                        }
                    }

                    if (TyAccountContext.isDebug()) {
                        log.info("checkFlowObjectContainsWorkFlow 对象的类型找到模板是否包含当前模板 flag ==> 【{}】", JSONObject.toJSONString(!flag));
                    }

                    if (flag) {
                        errorMessageSet.add(flowObject.getName() + "的流程模板不包含当前模板");
                    }
                }

                TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历流程对象 end");
            }

            TyplmLoggerUtil.debug(log, () -> "checkFlowObjectContainsWorkFlow 遍历类型 end");
            if (!errorMessageSet.isEmpty()) {
                String errorMessage = String.join(";", errorMessageSet);
                throw SystemErrorCodeEnum.ERROR_START_PROCESS_CUSTOM_MESSAGE.getException(new Object[]{errorMessage});
            }
        }
    }

    public List<WorkFlow> queryWorkflowByFlowObjectList(List<FlowObject> flowObjectList, BigInteger containerOid, String containerOtype) {
        if (TyAccountContext.isDebug()) {
            log.info("queryWorkflowByFlowObjectList 方法入参flowObjectList ==> 【{}】; containerOid ==> 【{}】; containerOtype ==> 【{}】", new Object[]{JSONObject.toJSONString(flowObjectList), JSONObject.toJSONString(containerOid), containerOtype});
        }

        if (org.apache.commons.collections.CollectionUtils.isEmpty(flowObjectList)) {
            return Collections.emptyList();
        } else {
            Set<BigInteger> typeOidSet = Collections.synchronizedSet(new HashSet());
            Map<BigInteger, Set<String>> typeLifeCycleStateMap = new ConcurrentHashMap();
            flowObjectList.parallelStream().forEach((flowObjectx) -> {
                BigInteger typeOid = flowObjectx.getTypeOid();
                typeOidSet.add(typeOid);
                if (!EntityBaseUtil.isEmptyOid(typeOid)) {
                    Set<String> lifeCycleStates = (Set)typeLifeCycleStateMap.computeIfAbsent(typeOid, (k) -> Collections.synchronizedSet(new HashSet()));
                    lifeCycleStates.add(flowObjectx.getLifeCycleStageKey());
                }
            });
            Set<BigInteger> typeOidAllSet = new HashSet();
            Map<BigInteger, List<BigInteger>> typeParentListMap = new HashMap();
            this.typlmWorkFlowRuleService.getAllParentTypeOid(typeOidSet, typeOidAllSet, typeParentListMap);
            if (containerOid == null && containerOtype == null) {
                for(FlowObject flowObject : flowObjectList) {
                    BigInteger flowObjectContainerOid = flowObject.getContainerOid();
                    String flowObjectContainerOtype = flowObject.getContainerOtype();
                    if (flowObjectContainerOid != null && flowObjectContainerOtype != null) {
                        containerOid = flowObjectContainerOid;
                        containerOtype = flowObjectContainerOtype;
                        break;
                    }
                }
            }

            return this.typlmWorkFlowRuleService.queryWorkflowByTypeAndLifeCycle(typeOidAllSet, typeLifeCycleStateMap, typeParentListMap, containerOid, containerOtype, (String)null);
        }
    }

    public String getMessageContent(WorkFlowContainer workFlowContainer) {
        TyplmLoggerUtil.debug(log, () -> "getMessageContent 方法入参workFlowContainer ==> 【{}】", () -> new Object[]{JSONObject.toJSONString(workFlowContainer)});
        List<WorkFlowObjectDTO> relationObject = this.getRelationObject(workFlowContainer);
        Map<String, List<String>> map = new HashMap();
        List<String> list = new ArrayList();

        for(WorkFlowObjectDTO workFlowObjectDTO : relationObject) {
            String refObjectOtype = workFlowObjectDTO.getRefObjectOtype();
            String refObjectName = workFlowObjectDTO.getRefObjectName();
            List<String> strings = (List)map.computeIfAbsent(refObjectOtype, (k) -> new ArrayList());
            if (strings.size() > 4) {
                list.add(refObjectOtype);
            } else {
                strings.add(refObjectName);
            }
        }

        Set<String> strings = map.keySet();
        List<TypeVueVO> typeVueVOS = this.typlmTypeService.queryTypeByInthIds(new ArrayList(strings));
        Map<String, String> typeDisplayNameMap = (Map)typeVueVOS.stream().collect(Collectors.toMap(TypeVueVO::getInthid, TypeVueVO::getDisplayName, (i, j) -> i));
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(workFlowContainer.getWorkFlowName());
        stringBuilder.append("中包含以下对象：<br/>");
        Iterator<Map.Entry<String, List<String>>> typeoIterator = map.entrySet().iterator();

        while(typeoIterator.hasNext()) {
            Map.Entry<String, List<String>> typeObjEntry = (Map.Entry)typeoIterator.next();
            String key = (String)typeObjEntry.getKey();
            String typeName = (String)typeDisplayNameMap.get(key);
            stringBuilder.append(typeName);
            stringBuilder.append(":");
            Iterator<String> objIterator = ((List)typeObjEntry.getValue()).iterator();

            while(objIterator.hasNext()) {
                stringBuilder.append((String)objIterator.next());
                if (objIterator.hasNext()) {
                    stringBuilder.append(";");
                }
            }

            if (!list.isEmpty() && list.contains(key)) {
                stringBuilder.append("等对象");
            }

            if (typeoIterator.hasNext()) {
                stringBuilder.append("<br/>");
            }
        }

        return stringBuilder.toString();
    }
}
